Commit ebe904dc authored by sagnowski's avatar sagnowski
Browse files

Simplify strong limiting logic

parent 2ad7a310
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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 ################################## */

+45 −1
Original line number Diff line number Diff line
@@ -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          */
#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 )
    {