From ebe904dcc9dd6caad06caae29d34921fb9ce30d7 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 3 Nov 2023 14:31:17 +0100 Subject: [PATCH 1/3] Simplify strong limiting logic --- lib_com/options.h | 1 + lib_rend/ivas_limiter.c | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7b61ed4b4a..c825b037b4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -156,6 +156,7 @@ #define FIX_890_ARRAY_SIZE /* Nokia: issue #890: mismatch in 2D array size declaration and use */ #define BE_FIX_887_GCC_WARNING_ARRAY_SIZE /* VoiceAge: Issue 887: change array size definition to avoid warning with gcc 11.4.0 */ #define FIX_247_EXTERNAL_RENDERER_COMMAND_LINE /* VA: issue 247: harmonize command-line options names of external renderer with the decoder */ +#define BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC /* #################### End BE switches ################################## */ diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index 0953e8a825..ae88208dea 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -51,9 +51,37 @@ static int16_t detect_strong_saturations( const int16_t BER_detect, /* i : BER detect flag */ int16_t *strong_saturation_cnt, /* i/o: counter of strong saturations */ const float max_val, /* i : maximum absolute value */ - float *frame_gain /* i/o: frame gain value */ +#ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC + const float *frame_gain /* i : frame gain value */ +#else + float *frame_gain /* i/o: frame gain value */ +#endif ) { +#ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC + if ( BER_detect ) + { + *strong_saturation_cnt = 50; + } + else if ( max_val > 3 * IVAS_LIMITER_THRESHOLD && *strong_saturation_cnt > 0 ) + { + /* strong_saturation_cnt stays unchanged. + * `if` condition still needs to be checked to avoid reaching the final `else` clause*/ + } + else if ( max_val > 10 * IVAS_LIMITER_THRESHOLD ) + { + *strong_saturation_cnt += 20; + *strong_saturation_cnt = min( *strong_saturation_cnt, 50 ); + } + else + { + ( *strong_saturation_cnt )--; + *strong_saturation_cnt = max( *strong_saturation_cnt, 0 ); + return 0; + } + + return *frame_gain < 0.3f; +#else int16_t apply_strong_limiting; apply_strong_limiting = 0; @@ -92,6 +120,7 @@ static int16_t detect_strong_saturations( } return apply_strong_limiting; +#endif } /*-------------------------------------------------------------------* @@ -328,12 +357,27 @@ void limiter_process( apply_strong_limiting = detect_strong_saturations( BER_detect, strong_saturation_cnt, max_val, &frame_gain ); } +#ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC + /* Apply strong limiting? */ + if ( apply_strong_limiting ) + { + frame_gain /= 3.0f; + } + /* ...otherwise limit gain reduction to 20dB. Any peaks that require gain reduction + * higher than this are most likely due to bit errors during decoding and should have + * been handled by the strong limiting mechanism */ + else if ( frame_gain < 0.1f ) + { + frame_gain = 0.1f; + } +#else /* Limit gain reduction to 20dB. Any peaks that require gain reduction * higher than this are most likely due to bit errors during decoding */ if ( frame_gain < 0.1f && !apply_strong_limiting ) { frame_gain = 0.1f; } +#endif if ( apply_limiting ) { -- GitLab From 257ec9a90ede0dc8b7dd6ddb652a9e22cb06bd96 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 3 Nov 2023 14:33:27 +0100 Subject: [PATCH 2/3] Pass frame_gain by value --- lib_rend/ivas_limiter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index ae88208dea..b179f65313 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -52,7 +52,7 @@ static int16_t detect_strong_saturations( int16_t *strong_saturation_cnt, /* i/o: counter of strong saturations */ const float max_val, /* i : maximum absolute value */ #ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC - const float *frame_gain /* i : frame gain value */ + const float frame_gain /* i : frame gain value */ #else float *frame_gain /* i/o: frame gain value */ #endif @@ -80,7 +80,7 @@ static int16_t detect_strong_saturations( return 0; } - return *frame_gain < 0.3f; + return frame_gain < 0.3f; #else int16_t apply_strong_limiting; @@ -354,7 +354,7 @@ void limiter_process( /* Detection of very strong saturations */ if ( strong_saturation_cnt != NULL ) { - apply_strong_limiting = detect_strong_saturations( BER_detect, strong_saturation_cnt, max_val, &frame_gain ); + apply_strong_limiting = detect_strong_saturations( BER_detect, strong_saturation_cnt, max_val, frame_gain ); } #ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC -- GitLab From acd0ce623b924104b85314d557593cd01baee075 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 3 Nov 2023 14:35:44 +0100 Subject: [PATCH 3/3] Fix formatting --- lib_rend/ivas_limiter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index b179f65313..ff6d4f3884 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -52,7 +52,7 @@ static int16_t detect_strong_saturations( int16_t *strong_saturation_cnt, /* i/o: counter of strong saturations */ const float max_val, /* i : maximum absolute value */ #ifdef BE_893_SIMPLIFY_STRONG_LIMITING_LOGIC - const float frame_gain /* i : frame gain value */ + const float frame_gain /* i : frame gain value */ #else float *frame_gain /* i/o: frame gain value */ #endif -- GitLab