Commit 676519ac authored by reutelhuber's avatar reutelhuber
Browse files

implement adaptive smoothing

parent f11d0041
Loading
Loading
Loading
Loading

lib_com/ivas_prot.h

100644 → 100755
+3 −1
Original line number Diff line number Diff line
@@ -3236,6 +3236,8 @@ void ivas_dirac_param_est_enc(
SBA_MODE ivas_sba_mode_select( 
#ifndef LBR_SBA
    const int32_t ivas_total_brate                              /* i  : IVAS total bitrate                      */
#else
    void
#endif
);

@@ -4134,7 +4136,7 @@ ivas_error ivas_spar_md_enc_process(
    const int16_t sba_order                                     /* i  : Ambisonic (SBA) order                   */
#ifdef LBR_SBA
    ,
    const float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]                                  /* i  : prior mixer_matrix     */
    float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]                                  /* i  : prior mixer_matrix     */
#endif
);

lib_com/options.h

100644 → 100755
+1 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@
#define LBR_SBA_EXTRA_COV_SMOOTH						/* Extra covariance smoothing for low bitrate SBA */
#endif
/*#define LBR_SBA_PLANAR*/                              /* Converting low bitrate SBA modes to Planar */
#define LBR_ADAP_SMOOTHING
#endif
/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */

lib_dec/ivas_spar_decoder.c

100644 → 100755
+118 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@
#include "ivas_prot.h"
#include "ivas_prot_rend.h"
#include "ivas_rom_com.h"
#ifdef LBR_ADAP_SMOOTHING
#include "ivas_rom_dec.h"
#endif
#include "ivas_stat_com.h"
#include <math.h>
#include <assert.h>
@@ -892,6 +895,88 @@ static void ivas_spar_get_skip_mat(
}


#ifdef LBR_ADAP_SMOOTHING
static void ivas_spar_calc_smooth_facs(
    float *cldfb_in_ts_re[CLDFB_NO_COL_MAX],
    float *cldfb_in_ts_im[CLDFB_NO_COL_MAX],
    int16_t nbands_spar,
    ivas_fb_bin_to_band_data_t *bin2band,
    float *smooth_fac,
    float smooth_buf[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1]
)
{
    int16_t b, bin, i, ts;
    float subframe_band_nrg[IVAS_MAX_NUM_BANDS];
    float smooth_long_avg[IVAS_MAX_NUM_BANDS];
    float smooth_short_avg[IVAS_MAX_NUM_BANDS];

    bin = 0;
    for ( b = 0; b < nbands_spar; b++ )
    {
        if ( b > 0 && bin2band->p_cldfb_map_to_spar_band[bin] < bin2band->p_cldfb_map_to_spar_band[bin - 1] )
        {
            break;
        }
        /* calculate band-wise subframe energies */
        subframe_band_nrg[b] = 0.f;
        while ( b == bin2band->p_cldfb_map_to_spar_band[bin] )
        {
            for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
            {
                subframe_band_nrg[b] += cldfb_in_ts_re[ts][bin] * cldfb_in_ts_re[ts][bin] + cldfb_in_ts_im[ts][bin] * cldfb_in_ts_im[ts][bin];
            }
            bin++;
        }
        subframe_band_nrg[b] = sqrtf( subframe_band_nrg[b] );
        smooth_buf[b][0] = subframe_band_nrg[b];

        /* calculate short and long energy averages */
        smooth_short_avg[b] = EPSILON;
        for ( i = 0; i < 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i++ )
        {
            smooth_short_avg[b] += smooth_buf[b][i];
        }

        smooth_long_avg[b] = smooth_short_avg[b];
        for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_SHORT; i < 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i++ )
        {
            smooth_long_avg[b] += smooth_buf[b][i];
        }
        smooth_short_avg[b] /= (2 * SBA_DIRAC_NRG_SMOOTH_SHORT);
        smooth_long_avg[b] /= (2 * SBA_DIRAC_NRG_SMOOTH_LONG);

        /* calculate smoothing factor based on energy averages */
        /* reduce factor for higher short-term energy */
        smooth_fac[b] = min( 1.f, smooth_long_avg[b] / smooth_short_avg[b] );
        /* map factor to range [0;1] */
        smooth_fac[b] = max( 0.f, smooth_fac[b] - (float)SBA_DIRAC_NRG_SMOOTH_SHORT / SBA_DIRAC_NRG_SMOOTH_LONG ) * ((float)SBA_DIRAC_NRG_SMOOTH_LONG / (SBA_DIRAC_NRG_SMOOTH_LONG - SBA_DIRAC_NRG_SMOOTH_SHORT));
        /* compress factor (higher compression in lowest bands) */
        if ( b < 2 )
        {
            smooth_fac[b] = powf( smooth_fac[b], 0.25f );
        }
        else
        {
            smooth_fac[b] = powf( smooth_fac[b], 0.5f );
        }

        /* apply upper bounds depending on band */
        smooth_fac[b] = max( min_smooth_gains1[b], min( max_smooth_gains2[b], smooth_fac[b] ) );
    }

    for ( b = 0; b < nbands_spar; b++ )
    {
        for ( i = 2 * SBA_DIRAC_NRG_SMOOTH_LONG; i > 0; i-- )
        {
            smooth_buf[b][i] = smooth_buf[b][i - 1];
        }
    }

    return;
}
#endif


/*-------------------------------------------------------------------*
 * ivas_spar_dec_upmixer()
 *
@@ -1094,11 +1179,31 @@ void ivas_spar_dec_upmixer(
            }
        }

#ifdef LBR_ADAP_SMOOTHING
        for ( in_ch = 0; in_ch < numch_in; in_ch++ )
        {
            ivas_spar_calc_smooth_facs( cldfb_in_ts_re[in_ch], cldfb_in_ts_im[in_ch], num_spar_bands, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac[in_ch], hSpar->hMdDec->smooth_buf[in_ch] );
        }
#endif

        for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ )
        {
            /* determine SPAR parameters for this time slots */
            ivas_spar_get_parameters( hSpar, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat );

#ifdef LBR_ADAP_SMOOTHING
            for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
            {
                for ( out_ch = 0; out_ch < numch_out; out_ch++ )
                {
                    for ( in_ch = 0; in_ch < numch_in; in_ch++ )
                    {
                        mixer_mat[out_ch][in_ch][spar_band] = (1 - hSpar->hMdDec->smooth_fac[in_ch][spar_band]) * mixer_mat[out_ch][in_ch][spar_band] + hSpar->hMdDec->smooth_fac[in_ch][spar_band] * hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band];
                    }
                }
            }
#endif

            for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ )
            {
                float out_re[IVAS_SPAR_MAX_CH];
@@ -1146,6 +1251,19 @@ void ivas_spar_dec_upmixer(
            }
        }

#ifdef LBR_ADAP_SMOOTHING
        for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ )
        {
            for ( out_ch = 0; out_ch < numch_out; out_ch++ )
            {
                for ( in_ch = 0; in_ch < numch_in; in_ch++ )
                {
                    hSpar->hMdDec->mixer_mat_prev2[out_ch][in_ch][spar_band] = mixer_mat[out_ch][in_ch][spar_band];
                }
            }
        }
#endif

        if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && hDecoderConfig->output_config != AUDIO_CONFIG_MONO )
        {
            ivas_dirac_dec( st_ivas, output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im, i_sf );

lib_dec/ivas_spar_md_dec.c

100644 → 100755
+21 −0
Original line number Diff line number Diff line
@@ -552,6 +552,27 @@ ivas_error ivas_spar_md_dec_init(
    set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS );
    set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS );

#ifdef LBR_ADAP_SMOOTHING
    for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ )
    {
        set_zero( hMdDec->smooth_fac[i], IVAS_MAX_NUM_BANDS );
    }
    for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ )
    {
        for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ )
        {
            set_zero( hMdDec->smooth_buf[i][j], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 );
        }
    }
    for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ )
    {
        for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ )
        {
            set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS );
        }
    }
#endif

    return IVAS_ERR_OK;
}

lib_dec/ivas_stat_dec.h

100644 → 100755
+5 −0
Original line number Diff line number Diff line
@@ -809,6 +809,11 @@ typedef struct ivas_spar_md_dec_state_t
    int16_t table_idx;
    int16_t dtx_vad;
    int16_t spar_hoa_md_flag;
#ifdef LBR_ADAP_SMOOTHING
    float smooth_buf[IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1];
    float smooth_fac[IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
    float mixer_mat_prev2[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
#endif

} ivas_spar_md_dec_state_t;

Loading