From 165e67de869b1dfb2865920aa04cdfec3e47e710 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 21 May 2025 14:37:24 +0200 Subject: [PATCH 1/2] port float MR 1401 --- lib_com/ari_hm.c | 16 ++++++++++++---- lib_com/options.h | 1 + lib_com/prot.h | 16 ++++++++++++---- lib_dec/ari_hm_dec.c | 14 +++++++++++--- lib_enc/ari_hm_enc.c | 30 +++++++++++++++++++++++------- 5 files changed, 59 insertions(+), 18 deletions(-) diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index 28a410933..abba7ef5d 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -205,8 +205,12 @@ int16_t CountIndexBits( *-------------------------------------------------------------------*/ int16_t tcx_hm_render( - const int16_t lag, /* i : pitch lag */ - const int16_t fract_res, /* i : fractional resolution of the lag */ +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, /* i : pitch lag */ +#else + const int16_t lag, /* i : pitch lag */ +#endif + const int16_t fract_res, /* i : fractional resolution of the lag */ Word16 p[] /* o : harmonic model (Q13) */ ) { @@ -265,8 +269,12 @@ int16_t tcx_hm_render( void tcx_hm_modify_envelope( const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, +#else + const int16_t lag, +#endif + 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 */ diff --git a/lib_com/options.h b/lib_com/options.h index 23bacc0d5..9fcaac652 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -219,6 +219,7 @@ #define FIX_ACCESS_WITHIN_NULL_STRUCT_MC_BW_SWITCHING /* FhG: fix usan error in MCT with bw swicthing */ #define NONBE_FIX_986_MC_BW_SWITCHING /* FhG: fix crash in bw and br switching with MC */ +#define FIX_1001_ARI_HM_OVERFLOW /* FhG: fix for undef behaviour in in the harmonic TCX model arithmetic coder */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_com/prot.h b/lib_com/prot.h index e79530df0..50d745705 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7833,15 +7833,23 @@ int16_t DecodeIndex( #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) int16_t tcx_hm_render( - const int16_t lag, /* i : pitch lag */ - const int16_t fract_res, /* i : fractional resolution of the lag */ +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, /* i : pitch lag */ +#else + const int16_t lag, /* i : pitch lag */ +#endif + const int16_t fract_res, /* i : fractional resolution of the lag */ Word16 p[] /* o : harmonic model (Q13) */ ); void tcx_hm_modify_envelope( const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, +#else + const int16_t lag, +#endif + 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 */ diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index a1e43ae97..e522c36c9 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -120,8 +120,12 @@ void tcx_hm_decode( int16_t *hm_bits /* o : bit consumption */ ) { - int16_t lag; - int32_t tmpL; +#ifdef FIX_1001_ARI_HM_OVERFLOW + int32_t lag; +#else + int16_t lag; +#endif + int32_t tmpL; int16_t NumTargetBits, fract_res; Word16 p[2 * kTcxHmParabolaHalfWidth + 1], gain; @@ -144,7 +148,11 @@ void tcx_hm_decode( /* Convert the index to lag */ UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, ( NumTargetBits <= kSmallerLagsTargetBitsThreshold ) || ( L_frame < 256 ), &fract_res, &tmpL ); - lag = (int16_t) tmpL; +#ifdef FIX_1001_ARI_HM_OVERFLOW + lag = tmpL; +#else + lag = (int16_t)tmpL; +#endif /* Render the harmonic model */ if ( tcx_hm_render( lag, fract_res, p ) ) diff --git a/lib_enc/ari_hm_enc.c b/lib_enc/ari_hm_enc.c index 56722df06..12ece4303 100644 --- a/lib_enc/ari_hm_enc.c +++ b/lib_enc/ari_hm_enc.c @@ -418,8 +418,12 @@ static void PeakFilter( static float tcx_hm_get_re( const float x[], /* i : absolute spectrum */ const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, +#else + const int16_t lag, +#endif + const int16_t fract_res, const Word16 p[], /* i : harmonic model (Q13) */ const Word32 env[], /* i : envelope (Q16) */ const int16_t L_frame /* i : number of spectral lines */ @@ -467,8 +471,12 @@ static float tcx_hm_get_re( static void tcx_hm_quantize_gain( const float x[], /* i : absolute spectrum */ const Word32 env[], /* i : envelope (Q16) */ - const int16_t lag, - const int16_t fract_res, +#ifdef FIX_1001_ARI_HM_OVERFLOW + const int32_t lag, +#else + const int16_t lag, +#endif + const int16_t fract_res, Word16 p[], /* i : harmonic model (Q13) */ const int16_t L_frame, /* i : number of spectral lines */ const int16_t coder_type, /* i : GC/VC coder type */ @@ -557,8 +565,12 @@ void tcx_hm_analyse( int16_t *hm_bits /* o : bit consumption */ ) { - int16_t lag; - int32_t tmpL; +#ifdef FIX_1001_ARI_HM_OVERFLOW + int32_t lag; +#else + int16_t lag; +#endif + int32_t tmpL; int16_t fract_res; float fspec[N_MAX_ARI], RelativeScore; Word16 p[2 * kTcxHmParabolaHalfWidth + 1], gain; @@ -583,7 +595,11 @@ void tcx_hm_analyse( /* Convert the index to lag */ UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, ( targetBits - *hm_bits <= kSmallerLagsTargetBitsThreshold ) || ( L_frame < 256 ), &fract_res, &tmpL ); - lag = (int16_t) tmpL; +#ifdef FIX_1001_ARI_HM_OVERFLOW + lag = tmpL; +#else + lag = (int16_t)tmpL; +#endif /* Render harmonic model */ tcx_hm_render( lag, fract_res, p ); -- GitLab From a4b5e74310b707a99c10650fecabfbe3725dedd2 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 21 May 2025 14:47:50 +0200 Subject: [PATCH 2/2] fix formatting --- lib_com/ari_hm.c | 12 ++++++------ lib_com/prot.h | 12 ++++++------ lib_dec/ari_hm_dec.c | 10 +++++----- lib_enc/ari_hm_enc.c | 22 +++++++++++----------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index abba7ef5d..e858a9ff2 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -206,11 +206,11 @@ int16_t CountIndexBits( int16_t tcx_hm_render( #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, /* i : pitch lag */ + const int32_t lag, /* i : pitch lag */ #else - const int16_t lag, /* i : pitch lag */ + const int16_t lag, /* i : pitch lag */ #endif - const int16_t fract_res, /* i : fractional resolution of the lag */ + const int16_t fract_res, /* i : fractional resolution of the lag */ Word16 p[] /* o : harmonic model (Q13) */ ) { @@ -270,11 +270,11 @@ int16_t tcx_hm_render( void tcx_hm_modify_envelope( const Word16 gain, /* i : HM gain (Q11) */ #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, + const int32_t lag, #else - const int16_t lag, + const int16_t lag, #endif - const int16_t fract_res, + 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 */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 50d745705..f02db6288 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7834,22 +7834,22 @@ int16_t DecodeIndex( int16_t tcx_hm_render( #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, /* i : pitch lag */ + const int32_t lag, /* i : pitch lag */ #else - const int16_t lag, /* i : pitch lag */ + const int16_t lag, /* i : pitch lag */ #endif - const int16_t fract_res, /* i : fractional resolution of the lag */ + const int16_t fract_res, /* i : fractional resolution of the lag */ Word16 p[] /* o : harmonic model (Q13) */ ); void tcx_hm_modify_envelope( const Word16 gain, /* i : HM gain (Q11) */ #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, + const int32_t lag, #else - const int16_t lag, + const int16_t lag, #endif - const int16_t fract_res, + 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 */ diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index e522c36c9..67be41d6e 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -121,11 +121,11 @@ void tcx_hm_decode( ) { #ifdef FIX_1001_ARI_HM_OVERFLOW - int32_t lag; + int32_t lag; #else - int16_t lag; + int16_t lag; #endif - int32_t tmpL; + int32_t tmpL; int16_t NumTargetBits, fract_res; Word16 p[2 * kTcxHmParabolaHalfWidth + 1], gain; @@ -149,9 +149,9 @@ void tcx_hm_decode( /* Convert the index to lag */ UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, ( NumTargetBits <= kSmallerLagsTargetBitsThreshold ) || ( L_frame < 256 ), &fract_res, &tmpL ); #ifdef FIX_1001_ARI_HM_OVERFLOW - lag = tmpL; + lag = tmpL; #else - lag = (int16_t)tmpL; + lag = (int16_t) tmpL; #endif /* Render the harmonic model */ diff --git a/lib_enc/ari_hm_enc.c b/lib_enc/ari_hm_enc.c index 12ece4303..cbbc1d976 100644 --- a/lib_enc/ari_hm_enc.c +++ b/lib_enc/ari_hm_enc.c @@ -419,11 +419,11 @@ static float tcx_hm_get_re( const float x[], /* i : absolute spectrum */ const Word16 gain, /* i : HM gain (Q11) */ #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, + const int32_t lag, #else - const int16_t lag, + const int16_t lag, #endif - const int16_t fract_res, + const int16_t fract_res, const Word16 p[], /* i : harmonic model (Q13) */ const Word32 env[], /* i : envelope (Q16) */ const int16_t L_frame /* i : number of spectral lines */ @@ -472,11 +472,11 @@ static void tcx_hm_quantize_gain( const float x[], /* i : absolute spectrum */ const Word32 env[], /* i : envelope (Q16) */ #ifdef FIX_1001_ARI_HM_OVERFLOW - const int32_t lag, + const int32_t lag, #else - const int16_t lag, + const int16_t lag, #endif - const int16_t fract_res, + const int16_t fract_res, Word16 p[], /* i : harmonic model (Q13) */ const int16_t L_frame, /* i : number of spectral lines */ const int16_t coder_type, /* i : GC/VC coder type */ @@ -566,11 +566,11 @@ void tcx_hm_analyse( ) { #ifdef FIX_1001_ARI_HM_OVERFLOW - int32_t lag; + int32_t lag; #else - int16_t lag; + int16_t lag; #endif - int32_t tmpL; + int32_t tmpL; int16_t fract_res; float fspec[N_MAX_ARI], RelativeScore; Word16 p[2 * kTcxHmParabolaHalfWidth + 1], gain; @@ -596,9 +596,9 @@ void tcx_hm_analyse( /* Convert the index to lag */ UnmapIndex( prm_hm[1], L_frame >= 256, LtpPitchLag, ( targetBits - *hm_bits <= kSmallerLagsTargetBitsThreshold ) || ( L_frame < 256 ), &fract_res, &tmpL ); #ifdef FIX_1001_ARI_HM_OVERFLOW - lag = tmpL; + lag = tmpL; #else - lag = (int16_t)tmpL; + lag = (int16_t) tmpL; #endif /* Render harmonic model */ -- GitLab