Commit f7278d9d authored by brownstef's avatar brownstef
Browse files

Merge branch '331-hbr-low-frequency-stuttering-fix' into 'main'

[non-BE] Resolve "HBR low frequency stuttering fix"

See merge request !417
parents f925ad10 5fe5d9a9
Loading
Loading
Loading
Loading
Loading
+115 −15
Original line number Diff line number Diff line
@@ -39,7 +39,9 @@
#include "wmc_auto.h"
#include "prot.h"


#ifdef SMOOTH_WITH_TRANS_DET
#define BAND_SMOOTH_REST_START_IDX ( 2 )
#endif
/*-----------------------------------------------------------------------------------------*
 * Function ivas_set_up_cov_smoothing()
 *
@@ -50,13 +52,23 @@ static void ivas_set_up_cov_smoothing(
    ivas_cov_smooth_state_t *hCovState,
    ivas_filterbank_t *pFb,
    const float max_update_rate,
    const int16_t min_pool_size )
    const int16_t min_pool_size
#ifdef COV_SMOOTH_TUNING
    ,
    const int16_t nchan_inp /* i  : number of input channels       */
#endif
)
{
    int16_t j, k;

#ifdef COV_SMOOTH_TUNING
    if ( nchan_inp <= FOA_CHANNELS )
    {
#endif
        for ( j = 0; j < pFb->filterbank_num_bands; j++ )
        {
        float update_factor = 0.0f;
            float update_factor;
            update_factor = 0.0f;

            for ( k = 0; k < pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; k++ )
            {
@@ -71,6 +83,31 @@ static void ivas_set_up_cov_smoothing(
            }
        }

#ifdef COV_SMOOTH_TUNING
    }
    else
    {
        for ( j = 0; j < pFb->filterbank_num_bands; j++ )
        {
            float update_factor;
            float *p_bin_to_band;
            int16_t active_bins;
            update_factor = 0.0f;
            p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j];
            active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j];
            for ( k = 0; k < active_bins; k++ )
            {
                update_factor += p_bin_to_band[k];
            }
            hCovState->pSmoothing_factor[j] = update_factor / min_pool_size;
            hCovState->pSmoothing_factor[j] *= ( j + 1 ) * 0.75f;
            if ( hCovState->pSmoothing_factor[j] > max_update_rate )
            {
                hCovState->pSmoothing_factor[j] = max_update_rate;
            }
        }
    }
#endif
    hCovState->prior_bank_idx = -1;

    return;
@@ -115,7 +152,12 @@ ivas_error ivas_spar_covar_smooth_enc_open(
        }
    }

    ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size );
    ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size
#ifdef COV_SMOOTH_TUNING
                               ,
                               nchan_inp
#endif
    );

    *hCovState_out = hCovState;

@@ -176,14 +218,66 @@ static void ivas_compute_smooth_cov(
    const int16_t start_band,
    const int16_t end_band,
    const int16_t num_ch,
    const int16_t transient_det )
#ifdef SMOOTH_WITH_TRANS_DET
    const int16_t transient_det[2]
#else
    const int16_t transient_det
#endif
)
{
    int16_t i, j, k;
    int16_t prev_idx = hCovState->prior_bank_idx;
    float factor = 0;
#ifdef SMOOTH_WITH_TRANS_DET
    int16_t sm_b;
    int16_t non_sm_b_idx;
    sm_b = BAND_SMOOTH_REST_START_IDX;
#endif

    assert( end_band <= pFb->filterbank_num_bands );

#ifdef SMOOTH_WITH_TRANS_DET
    if ( prev_idx == -1 || transient_det[1] == 1 )
    {
        for ( i = 0; i < num_ch; i++ )
        {
            for ( k = start_band; k < end_band; k++ )
            {
                pCov_buf[i][i][k] += ( hCovState->pSmoothing_factor[k] * fac );
            }
        }
    }
    else if ( transient_det[0] == 1 )
    {
        non_sm_b_idx = min( sm_b, end_band );
        for ( i = 0; i < num_ch; i++ )
        {
            for ( j = 0; j < num_ch; j++ )
            {
                if ( i == j )
                {
                    factor = fac;
                }
                else
                {
                    factor = 0.0f;
                }

                for ( k = start_band; k < non_sm_b_idx; k++ )
                {
                    pCov_buf[i][j][k] = pPrior_cov_buf[i][j][k] + ( hCovState->pSmoothing_factor[k] * ( pCov_buf[i][j][k] - pPrior_cov_buf[i][j][k] + factor ) );
                }
            }
        }
        for ( i = 0; i < num_ch; i++ )
        {
            for ( k = non_sm_b_idx; k < end_band; k++ )
            {
                pCov_buf[i][i][k] += ( hCovState->pSmoothing_factor[k] * fac );
            }
        }
    }
#else
    if ( prev_idx == -1 || transient_det == 1 )
    {
        for ( i = 0; i < num_ch; i++ )
@@ -194,6 +288,7 @@ static void ivas_compute_smooth_cov(
            }
        }
    }
#endif
    else if ( prev_idx == 0 )
    {
        for ( i = 0; i < num_ch; i++ )
@@ -234,7 +329,12 @@ void ivas_cov_smooth_process(
    const int16_t start_band,
    const int16_t end_band,
    const int16_t num_ch,
    const int16_t transient_det )
#ifdef SMOOTH_WITH_TRANS_DET
    const int16_t transient_det[2]
#else
    const int16_t transient_det
#endif
)
{
    int16_t i, j;
    int16_t num_bands = end_band - start_band;
+17 −0
Original line number Diff line number Diff line
@@ -4189,7 +4189,11 @@ void ivas_enc_cov_handler_process(
    const int16_t end_band,
    const int16_t nchan_inp,
    const int16_t dtx_vad,
#ifdef SMOOTH_WITH_TRANS_DET
    const int16_t transient_det[2]
#else
    const int16_t transient_det
#endif
);

ivas_error ivas_spar_covar_smooth_enc_open( 
@@ -4211,7 +4215,11 @@ void ivas_cov_smooth_process(
    const int16_t start_band,
    const int16_t end_band,
    const int16_t num_ch,
#ifdef SMOOTH_WITH_TRANS_DET
    const int16_t transient_det[2]
#else
    const int16_t transient_det
#endif
);

/* Transient detector module */
@@ -4224,11 +4232,20 @@ void ivas_spar_transient_det_close(
    ivas_trans_det_state_t **hTranDet                           /* i/o: SPAR TD  handle                         */
);

#ifdef SMOOTH_WITH_TRANS_DET
void ivas_transient_det_process( 
    ivas_trans_det_state_t *hTranDet,                           /* i/o: SPAR TD handle                          */
    float *pIn_pcm,                                             /* i  : input audio channels                    */
    const int16_t frame_len,                                     /* i  : frame length in samples                 */
    int16_t transient_det[2]                                         /* o: transient det outputs                         */
);
#else
int16_t ivas_transient_det_process( 
    ivas_trans_det_state_t *hTranDet,                           /* i/o: SPAR TD handle                          */
    float *pIn_pcm,                                             /* i  : input audio channels                    */
    const int16_t frame_len                                     /* i  : frame length in samples                 */
);
#endif

void ivas_td_decorr_get_ducking_gains( 
    ivas_trans_det_state_t *hTranDet,                           /* i/o: SPAR TD handle                          */
+44 −2
Original line number Diff line number Diff line
@@ -211,16 +211,31 @@ void ivas_spar_transient_det_close(
 *
 * Transient detection process call
 *-----------------------------------------------------------------------------------------*/

#ifdef SMOOTH_WITH_TRANS_DET
void ivas_transient_det_process(
    ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle                          */
    float *pIn_pcm,                   /* i  : input audio channels                    */
    const int16_t frame_len,          /* i  : frame length in samples                 */
    int16_t transient_det[2]          /* o: transient det outputs                         */
)
#else
int16_t ivas_transient_det_process(
    ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle                */
    float *pIn_pcm,                   /* i  : input audio channels          */
    const int16_t frame_len           /* i  : frame length in samples       */
)
#endif
{
    float mem = hTranDet->in_duck_gain;
#ifdef SMOOTH_WITH_TRANS_DET
    float in_duck_gain[L_FRAME48k];
    int16_t num_sf, sf, sf_samp, idx;
#else
    int16_t trans;
#endif
    float mem = hTranDet->in_duck_gain;


#ifndef SMOOTH_WITH_TRANS_DET
    ivas_td_decorr_get_ducking_gains( hTranDet, pIn_pcm, NULL, NULL, frame_len, IVAS_TDET_ONLY );

    if ( mem - hTranDet->in_duck_gain > IVAS_TDET_PARM_TRANS_THR )
@@ -233,6 +248,30 @@ int16_t ivas_transient_det_process(
    }

    return trans;
#else
    ivas_td_decorr_get_ducking_gains( hTranDet, pIn_pcm, in_duck_gain, NULL, frame_len, IVAS_TDET_ONLY );

    transient_det[0] = 0;
    transient_det[1] = 0;
    if ( mem - hTranDet->in_duck_gain > IVAS_TDET_PARM_TRANS_THR )
    {
        transient_det[0] = 1;
    }

    num_sf = 16;
    sf_samp = frame_len / num_sf;
    for ( sf = 1; sf <= num_sf; sf++ )
    {
        idx = ( sf_samp * sf ) - 1;
        if ( ( mem - in_duck_gain[idx] ) > ( IVAS_TDET_PARM_TRANS_THR * 1.1f ) )
        {
            transient_det[1] = 1;
        }
        mem = in_duck_gain[idx];
    }
    // dbgwrite( &transient_det[1], sizeof( int16_t ), 1, 1, "trans_det.raw" );
    return;
#endif
}


@@ -306,6 +345,9 @@ void ivas_td_decorr_get_ducking_gains(
        for ( i = 0; i < frame_len; i++ )
        {
            in_duck_gain = ivas_calc_duck_gain( in_duck_gain, in_duck_coeff, e_slow[i], e_fast[i], duck_mult_fac );
#ifdef SMOOTH_WITH_TRANS_DET
            pIn_duck_gains[i] = in_duck_gain;
#endif
        }
        hTranDet->in_duck_gain = in_duck_gain;
    }
+8 −0
Original line number Diff line number Diff line
@@ -167,6 +167,14 @@

#define FIX_107_5MS_SUBFRAME_RENDERING                  /* Issue 107: use 5ms subframes everywhere in parametric binauralizer */

#define FIX_331_SBA_HBR_HOA_FIXES                       /* DLB: issue 331 - fix addressing low frequency stuttering with HOA inputs at high bitrates */
#ifdef FIX_331_SBA_HBR_HOA_FIXES
#define COV_SMOOTH_TUNING
#define SBA_HPF_TUNING_ENC
/*#define SBA_HPF_TUNING_DEC*/
#define SMOOTH_WITH_TRANS_DET
#endif

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
#endif
+13 −0
Original line number Diff line number Diff line
@@ -327,7 +327,20 @@ ivas_error ivas_dec(

        /* HP filtering */
#ifndef DEBUG_SPAR_BYPASS_EVS_CODEC
#ifdef SBA_HPF_TUNING_DEC
        int16_t nchan_hp20;
        if ( st_ivas->ivas_format == MASA_FORMAT )
        {
            nchan_hp20 = nchan_remapped;
        }
        else
        {
            nchan_hp20 = getNumChanSynthesis( st_ivas );
        }
        for ( n = 0; n < nchan_hp20; n++ )
#else
        for ( n = 0; n < nchan_remapped; n++ )
#endif
        {
            hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
        }
Loading