From 0f66ff04a9fe6acb74ff6e236d1181fb24e027c0 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 17 Dec 2025 09:39:06 +0100 Subject: [PATCH 1/3] Corrects constant 1/128 for index generation in create_random_vector() --- lib_com/options.h | 1 + lib_com/prot.h | 3 +++ lib_com/swb_tbe_com.c | 57 +++++++++++++++++++++++++++++++++++++++++++ lib_dec/swb_tbe_dec.c | 4 +++ lib_enc/swb_tbe_enc.c | 4 +++ 5 files changed, 69 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 57c086afb3..b5b0b05548 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,6 +181,7 @@ #define FIX_1461_CNG_BW_SWITCHING /* Eri: issue 1461: Stereo parameters are not updated when SID/NODATA forces BW to stay the same */ #define FIX_2252_LP_CNG_STARTS_SID /* VA: issues 2251 and 2252: fix LP CNG uninitialized value in bitstream that starts with an SID */ #define FIX_1381_BWD /* VA: issue 1381: apply no hysteresis in BWD at higher bitrates also in mono MASA and OMASA */ +#define FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION /* Dolby: issue 1465: Fix constant in create_random_vector() to allow more reliable fixed point port */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/prot.h b/lib_com/prot.h index c624212fc3..ae644cf530 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2685,6 +2685,9 @@ void GenShapedWBExcitation( float *mem_genSHBexc_filt_down3, /* i/o: memory */ float *state_lpc_syn, /* i/o: memory */ const int16_t coder_type, /* i : coding type */ +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + const int16_t element_mode, /* i : element mode */ +#endif const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ int16_t bwe_seed[], /* i/o: random number generator seed */ const float voice_factors[], /* i : voicing factor */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 2104e5cdee..e1bb4cbc2e 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -54,7 +54,11 @@ * Local function prototypes *-----------------------------------------------------------------*/ +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION +static void create_random_vector( float output[], const int16_t length, int16_t seed[], const int16_t element_mode ); +#else static void create_random_vector( float output[], const int16_t length, int16_t seed[] ); +#endif static void flip_spectrum( const float input[], float output[], const int16_t length ); static void Hilbert_transform( float tmp_R[], float tmp_I[], float *tmpi_R, float *tmpi_I, const int16_t length, const int16_t HB_stage_id ); 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 ); @@ -366,6 +370,9 @@ void GenShapedWBExcitation( float *mem_genSHBexc_filt_down3, /* i/o: memory */ float *state_lpc_syn, /* i/o: memory */ const int16_t coder_type, /* i : coding type */ +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + const int16_t element_mode, /* i : element mode */ +#endif const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ int16_t bwe_seed[], /* i/o: random number generator seed */ const float voice_factors[], /* i : voicing factor */ @@ -407,7 +414,11 @@ void GenShapedWBExcitation( if ( uv_flag ) { /* unvoiced signal */ +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + create_random_vector( exc4kWhtnd, L_FRAME16k / 4, bwe_seed, element_mode ); +#else create_random_vector( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); +#endif } else { @@ -436,7 +447,11 @@ void GenShapedWBExcitation( *mem_csfilt = -csfilt_den2[1] * excNoisyEnv[i]; } +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + create_random_vector( exc4k, L_FRAME16k / 4, bwe_seed, element_mode ); +#else create_random_vector( exc4k, L_FRAME16k / 4, bwe_seed ); +#endif /* Ensure pow22 is greater than zero when computing normalization */ for ( i = 0, pow22 = 0.00001f; i < L_FRAME16k / 4; i++ ) @@ -890,8 +905,13 @@ void GenShapedSHBExcitation( } else { +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + create_random_vector( White_exc16k, L_FRAME, bwe_seed, element_mode ); + create_random_vector( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); +#else create_random_vector( White_exc16k, L_FRAME, bwe_seed ); create_random_vector( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); +#endif for ( k = 0, pow22 = 0.00001f; k < L_FRAME16k; k++ ) { @@ -1535,23 +1555,60 @@ void non_linearity( * -------------------------------------------------------------------*/ void create_random_vector( +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + float output[], /* o : output random vector */ + const int16_t length, /* i : length of random vector */ + int16_t seed[], /* i/o: start seed */ + const int16_t element_mode /* i : element mode */ +#else float output[], /* o : output random vector */ const int16_t length, /* i : length of random vector */ int16_t seed[] /* i/o: start seed */ +#endif ) { int16_t i, j, k; float scale1, scale2; +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + if ( element_mode != EVS_MONO ) + { + j = (int16_t) ( own_random( &seed[0] ) * 0.0078125f ); + j = min( abs( j ), 255 ); + k = (int16_t) ( own_random( &seed[1] ) * 0.0078125f ); + k = min( abs( k ), 255 ); + } + else + { + j = (int16_t) ( own_random( &seed[0] ) * 0.0078f ); + j = abs( j ) & 0xff; + k = (int16_t) ( own_random( &seed[1] ) * 0.0078f ); + k = abs( k ) & 0xff; + } +#else j = (int16_t) ( own_random( &seed[0] ) * 0.0078f ); j = abs( j ) & 0xff; k = (int16_t) ( own_random( &seed[1] ) * 0.0078f ); k = abs( k ) & 0xff; +#endif while ( k == j ) { +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + if ( element_mode != EVS_MONO ) + { + k = (int16_t) ( own_random( &seed[1] ) * 0.0078125f ); + k = min( abs( k ), 255 ); + } + else + { + k = (int16_t) ( own_random( &seed[1] ) * 0.0078f ); + k = abs( k ) & 0xff; + } +#else k = (int16_t) ( own_random( &seed[1] ) * 0.0078f ); k = abs( k ) & 0xff; +#endif } if ( own_random( &seed[0] ) < 0 ) diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 8f88f5150e..8e43b9fd03 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -323,7 +323,11 @@ void wb_tbe_dec( /* From low band excitation, generate highband excitation */ mvr2r( hBWE_TD->state_syn_shbexc, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, st->element_mode, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf ); +#else GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf ); +#endif prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD / 4 ); curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD / 4, L_SHB_LAHEAD / 4 ); diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index b1363db100..b5484d9abc 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -378,7 +378,11 @@ void wb_tbe_enc( /* From low band excitation, generate highband excitation */ mvr2r( hBWE_TD->state_syn_shbexc, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); +#ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION + GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, st->element_mode, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf ); +#else GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf ); +#endif prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD / 4 ); curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD / 4, L_SHB_LAHEAD / 4 ); -- GitLab From 8cb18a964857a30a7d22a6ecb18d44389868c745 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 17 Dec 2025 10:36:46 +0100 Subject: [PATCH 2/3] Applies clang format check patch --- lib_com/prot.h | 10 +++++----- lib_com/swb_tbe_com.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index ae644cf530..29fc601844 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2686,12 +2686,12 @@ void GenShapedWBExcitation( float *state_lpc_syn, /* i/o: memory */ const int16_t coder_type, /* i : coding type */ #ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION - const int16_t element_mode, /* i : element mode */ + const int16_t element_mode, /* i : element mode */ #endif - const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ - int16_t bwe_seed[], /* i/o: random number generator seed */ - const float voice_factors[], /* i : voicing factor */ - const int16_t uv_flag, /* i : unvoiced flag */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + int16_t bwe_seed[], /* i/o: random number generator seed */ + const float voice_factors[], /* i : voicing factor */ + const int16_t uv_flag, /* i : unvoiced flag */ const int16_t igf_flag ); void GenWBSynth( diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index e1bb4cbc2e..a7eef08f0a 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -371,12 +371,12 @@ void GenShapedWBExcitation( float *state_lpc_syn, /* i/o: memory */ const int16_t coder_type, /* i : coding type */ #ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION - const int16_t element_mode, /* i : element mode */ + const int16_t element_mode, /* i : element mode */ #endif - const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ - int16_t bwe_seed[], /* i/o: random number generator seed */ - const float voice_factors[], /* i : voicing factor */ - const int16_t uv_flag, /* i : unvoiced flag */ + const float *bwe_exc_extended, /* i : bandwidth extended exciatation */ + int16_t bwe_seed[], /* i/o: random number generator seed */ + const float voice_factors[], /* i : voicing factor */ + const int16_t uv_flag, /* i : unvoiced flag */ const int16_t igf_flag ) { int16_t i, j, k; -- GitLab From caa7dea44bc5b1598274ed167a824c3689a99fd3 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 17 Dec 2025 11:02:28 +0100 Subject: [PATCH 3/3] Adds explicit cast to int16_t to fix warning --- lib_com/swb_tbe_com.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index a7eef08f0a..4e20e49810 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -1574,9 +1574,9 @@ void create_random_vector( if ( element_mode != EVS_MONO ) { j = (int16_t) ( own_random( &seed[0] ) * 0.0078125f ); - j = min( abs( j ), 255 ); + j = (int16_t) min( abs( j ), 255 ); k = (int16_t) ( own_random( &seed[1] ) * 0.0078125f ); - k = min( abs( k ), 255 ); + k = (int16_t) min( abs( k ), 255 ); } else { @@ -1598,7 +1598,7 @@ void create_random_vector( if ( element_mode != EVS_MONO ) { k = (int16_t) ( own_random( &seed[1] ) * 0.0078125f ); - k = min( abs( k ), 255 ); + k = (int16_t) min( abs( k ), 255 ); } else { -- GitLab