From 095a68a4157089f9c176d63209fc0f110901526d Mon Sep 17 00:00:00 2001 From: Simon Plain Date: Fri, 19 May 2023 11:15:25 +0200 Subject: [PATCH 1/2] Fix covariance smoothing for ParamUpmix --- lib_com/cnst.h | 8 ++++ lib_com/ivas_cov_smooth.c | 77 +++++++++++++++++++++++++------- lib_com/ivas_prot.h | 6 +++ lib_com/options.h | 2 + lib_enc/ivas_enc_cov_handler.c | 21 +++++++++ lib_enc/ivas_mc_paramupmix_enc.c | 4 ++ lib_enc/ivas_spar_encoder.c | 4 ++ 7 files changed, 106 insertions(+), 16 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index cd3aa07c48..709308bcae 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -2244,5 +2244,13 @@ enum VOIP_RTPDUMP }; +#ifdef FIX_489_COV_SMOOTHING +enum +{ + COV_SMOOTH_SPAR, + COV_SMOOTH_MC +}; +#endif + /* clang-format on */ #endif /* CNST_H */ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 7a24396606..21c5ed0b0e 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -39,6 +39,10 @@ #include "wmc_auto.h" #include "prot.h" +#ifdef FIX_489_COV_SMOOTHING +#include "cnst.h" +#endif + #define BAND_SMOOTH_REST_START_IDX ( 2 ) /*-----------------------------------------------------------------------------------------* * Function ivas_set_up_cov_smoothing() @@ -51,6 +55,10 @@ static void ivas_set_up_cov_smoothing( ivas_filterbank_t *pFb, const float max_update_rate, const int16_t min_pool_size +#ifdef FIX_489_COV_SMOOTHING + , + const int16_t smooth_mode /* i : flag multichannel vs SPAR */ +#endif #ifndef FIX_331_ALL_BRS , const int16_t nchan_inp /* i : number of input channels */ @@ -93,9 +101,8 @@ static void ivas_set_up_cov_smoothing( } } } - else -#ifndef FIX_331_ALL_BRS - if ( nchan_inp <= FOA_CHANNELS ) +#ifdef FIX_489_COV_SMOOTHING + else if ( smooth_mode == COV_SMOOTH_MC ) { for ( j = 0; j < pFb->filterbank_num_bands; j++ ) { @@ -118,25 +125,52 @@ static void ivas_set_up_cov_smoothing( else { #endif - for ( j = 0; j < pFb->filterbank_num_bands; j++ ) +#ifndef FIX_331_ALL_BRS + if ( nchan_inp <= FOA_CHANNELS ) { - 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++ ) + for ( j = 0; j < pFb->filterbank_num_bands; j++ ) { - update_factor += p_bin_to_band[k]; + float update_factor; + update_factor = 0.0f; + + for ( k = 0; k < pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; k++ ) + { + update_factor += pFb->fb_bin_to_band.pFb_bin_to_band[j][k]; + } + + hCovState->pSmoothing_factor[j] = update_factor / min_pool_size; + + if ( hCovState->pSmoothing_factor[j] > max_update_rate ) + { + hCovState->pSmoothing_factor[j] = max_update_rate; + } } - 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 ) + } + else + { +#endif + for ( j = 0; j < pFb->filterbank_num_bands; j++ ) { - hCovState->pSmoothing_factor[j] = max_update_rate; + 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; + } } +#ifdef FIX_489_COV_SMOOTHING } +#endif #ifndef FIX_331_ALL_BRS } #endif @@ -158,6 +192,9 @@ ivas_error ivas_spar_covar_smooth_enc_open( ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t nchan_inp /* i : number of input channels */ , +#ifdef FIX_489_COV_SMOOTHING + int16_t smooth_mode, +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { @@ -188,9 +225,17 @@ ivas_error ivas_spar_covar_smooth_enc_open( #ifndef FIX_331_ALL_BRS +#ifdef FIX_489_COV_SMOOTHING + ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); +#else ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, nchan_inp, ivas_total_brate ); +#endif +#else +#ifdef FIX_489_COV_SMOOTHING + ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate ); #else ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, ivas_total_brate ); +#endif #endif *hCovState_out = hCovState; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5d4faf0eb0..092851d49e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4794,6 +4794,9 @@ ivas_error ivas_spar_covar_enc_open( const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp /* i : number of input channels */ , +#ifdef FIX_489_COV_SMOOTHING + int16_t smooth_mode, +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); @@ -4826,6 +4829,9 @@ ivas_error ivas_spar_covar_smooth_enc_open( ivas_filterbank_t *pFb, /* i/o: FB handle */ const int16_t nchan_inp /* i : number of input channels */ , +#ifdef FIX_489_COV_SMOOTHING + int16_t smooth_mode, +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); diff --git a/lib_com/options.h b/lib_com/options.h index be54df0c71..a31105684b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -223,6 +223,8 @@ #define FIX_487_LOWRATE_SBA_TUNING_FIX /* Dlb: TUning fix for low bitrate cases to match theoretical longest SPAR MD bitstream */ +#define FIX_489_COV_SMOOTHING /* Dlb: Fix covariance smoothing for ParamUpmix */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 6575d751a9..9b3337126f 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -75,6 +75,9 @@ ivas_error ivas_spar_covar_enc_open( const int32_t input_Fs, /* i : input sampling rate */ const int16_t nchan_inp /* i : number of input channels */ , +#ifdef FIX_489_COV_SMOOTHING + int16_t smooth_mode, +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) { @@ -92,6 +95,15 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE; +#ifdef FIX_489_COV_SMOOTHING +#ifdef MC_PARAMUPMIX_MODE + if ( smooth_mode == COV_SMOOTH_MC ) + { + cov_smooth_cfg.max_update_rate = 1.0f; + cov_smooth_cfg.min_pool_size = 20; + } +#endif +#else #ifdef MC_PARAMUPMIX_MODE if ( nchan_inp == 3 ) /* to discriminate between SPAR and mc there could be a better solution */ { @@ -99,8 +111,13 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.min_pool_size = 20; } #endif +#endif +#ifdef FIX_489_COV_SMOOTHING + if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_state, &cov_smooth_cfg, pFb, nchan_inp, ivas_total_brate ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -108,7 +125,11 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE_DTX; cov_smooth_cfg.min_pool_size = MIN_POOL_SIZE_DTX; +#ifdef FIX_489_COV_SMOOTHING + if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp, smooth_mode, ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_smooth_enc_open( &hCovState->pCov_dtx_state, &cov_smooth_cfg, pFb, nchan_inp, ivas_total_brate ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 6363ee3b13..945f5af665 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -211,7 +211,11 @@ ivas_error ivas_mc_paramupmix_enc_open( for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { /* Covariance handle */ +#ifdef FIX_489_COV_SMOOTHING + if ( ( error = ivas_spar_covar_enc_open( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, COV_SMOOTH_MC, st_ivas->hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_enc_open( &( hMCParamUpmix->hCovEnc[i] ), hMCParamUpmix->hFbMixer->pFb, input_Fs, MC_PARAMUPMIX_NCH + 1, st_ivas->hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index a7c359b7c9..362acbf2aa 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -146,7 +146,11 @@ ivas_error ivas_spar_enc_open( } /* Covariance handle */ +#ifdef FIX_489_COV_SMOOTHING + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, COV_SMOOTH_SPAR, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp, hEncoderConfig->ivas_total_brate ) ) != IVAS_ERR_OK ) +#endif { return error; } -- GitLab From 20e060837432cce77ea22c40ca3c0f3229c56bc1 Mon Sep 17 00:00:00 2001 From: Simon Plain Date: Wed, 24 May 2023 11:23:59 +0200 Subject: [PATCH 2/2] Change enum to typedef enum --- lib_com/cnst.h | 4 ++-- lib_com/ivas_cov_smooth.c | 11 +++++------ lib_com/ivas_prot.h | 4 ++-- lib_enc/ivas_enc_cov_handler.c | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 15582180c0..a35f5280c2 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -2241,11 +2241,11 @@ enum }; #ifdef FIX_489_COV_SMOOTHING -enum +typedef enum _COV_SMOOTHING_TYPE { COV_SMOOTH_SPAR, COV_SMOOTH_MC -}; +} COV_SMOOTHING_TYPE; #endif /* clang-format on */ diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 219c315a07..e407bccc6c 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -35,13 +35,12 @@ #ifdef DEBUGGING #include "debug.h" #endif -#include "ivas_prot.h" -#include "wmc_auto.h" -#include "prot.h" - #ifdef FIX_489_COV_SMOOTHING #include "cnst.h" #endif +#include "ivas_prot.h" +#include "wmc_auto.h" +#include "prot.h" #define BAND_SMOOTH_REST_START_IDX ( 2 ) /*-----------------------------------------------------------------------------------------* @@ -57,7 +56,7 @@ static void ivas_set_up_cov_smoothing( const int16_t min_pool_size #ifdef FIX_489_COV_SMOOTHING , - const int16_t smooth_mode /* i : flag multichannel vs SPAR */ + const COV_SMOOTHING_TYPE smooth_mode /* i : flag multichannel vs SPAR */ #endif , const int32_t ivas_total_brate ) @@ -161,7 +160,7 @@ ivas_error ivas_spar_covar_smooth_enc_open( const int16_t nchan_inp /* i : number of input channels */ , #ifdef FIX_489_COV_SMOOTHING - int16_t smooth_mode, /* i : Smooth covariance for SPAR or MC */ + COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ #endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 36db649e09..650473d852 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4734,7 +4734,7 @@ ivas_error ivas_spar_covar_enc_open( const int16_t nchan_inp /* i : number of input channels */ , #ifdef FIX_489_COV_SMOOTHING - int16_t smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ #endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); @@ -4767,7 +4767,7 @@ ivas_error ivas_spar_covar_smooth_enc_open( const int16_t nchan_inp /* i : number of input channels */ , #ifdef FIX_489_COV_SMOOTHING - int16_t smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ #endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 905a55d333..61c4ccaef9 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -69,7 +69,7 @@ ivas_error ivas_spar_covar_enc_open( const int16_t nchan_inp /* i : number of input channels */ , #ifdef FIX_489_COV_SMOOTHING - int16_t smooth_mode, /* i : Smooth covariance for SPAR or MC */ + COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ #endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ) -- GitLab