diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 261b1d38a8113ae3b90389bd90b7b20ee274554f..63e80cd8be240421d6d6e2eaced7516bbde8b3cb 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3386,10 +3386,27 @@ void ivas_dirac_dec( const int16_t i_sf ); +#ifdef FIX_417_TD_DECORR_BRATE_SW +ivas_error ivas_td_decorr_reconfig_dec( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : total IVAS bitrate */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */ + uint16_t *useTdDecorr /* i/o: TD decorrelator flag */ +); + +/*! r: Configured reqularization factor value */ +float configure_reqularization_factor( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : total IVAS bitrate */ +); +#else ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ ); +#endif void computeDiffuseness_mdft( float **buffer_intensity[DIRAC_NUM_DIMS], diff --git a/lib_com/ivas_td_decorr.c b/lib_com/ivas_td_decorr.c index 23620b3b2db5dc6db7e83828c615efef98faba5e..0215bfcf56b5b682143cc448e5eaf76d81186556 100644 --- a/lib_com/ivas_td_decorr.c +++ b/lib_com/ivas_td_decorr.c @@ -87,12 +87,111 @@ static const float ivas_three_pow_frac[IVAS_MAX_DECORR_APD_SECTIONS] = { }; +#ifdef FIX_417_TD_DECORR_BRATE_SW +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#endif + /*------------------------------------------------------------------------------------------* * Local functions declaration *------------------------------------------------------------------------------------------*/ static int16_t ivas_get_APD_filt_orders( const int16_t num_out_chans, const int32_t output_Fs, int16_t *APD_filt_orders ); -static ivas_error ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); + +static void ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ); + + +#ifdef FIX_417_TD_DECORR_BRATE_SW +/*------------------------------------------------------------------------- + * ivas_td_decorr_reconfig_dec() + * + * Allocate and initialize time domain decorrelator handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_td_decorr_reconfig_dec( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : total IVAS bitrate */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + ivas_td_decorr_state_t **hTdDecorr, /* i/o: TD decorrelator handle */ + uint16_t *useTdDecorr /* i/o: TD decorrelator flag */ +) +{ + uint16_t useTdDecorr_new; + ivas_error error; + + useTdDecorr_new = 0; + if ( ivas_format == SBA_FORMAT ) + { + if ( nchan_transport == 1 ) + { + useTdDecorr_new = 1; + } + } + else if ( ivas_format == MASA_FORMAT ) + { + if ( ( ivas_total_brate < IVAS_48k && nchan_transport == 1 ) || ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + { + useTdDecorr_new = 1; + } + } + else if ( ivas_format == MC_FORMAT ) + { + if ( ivas_total_brate < IVAS_48k && nchan_transport == 1 ) + { + useTdDecorr_new = 1; + } + } + + if ( *useTdDecorr != useTdDecorr_new ) + { + *useTdDecorr = useTdDecorr_new; + + if ( *useTdDecorr ) + { + if ( ivas_total_brate >= IVAS_13k2 && ivas_format == SBA_FORMAT ) + { + if ( *hTdDecorr == NULL ) + { + if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_total_brate < IVAS_24k4 ) + { + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR; + } + else + { + ( *hTdDecorr )->pTrans_det->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC_PARA_BIN; + } + } + else + { + if ( *hTdDecorr == NULL ) + { + if ( ( error = ivas_td_decorr_dec_open( hTdDecorr, output_Fs, 3, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + ivas_td_decorr_init( *hTdDecorr, 3, 0 ); + } + } + } + else + { + ivas_td_decorr_dec_close( hTdDecorr ); + } + } + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- @@ -275,7 +374,7 @@ static int16_t ivas_get_APD_filt_orders( * TD decorr Initialisation function *-----------------------------------------------------------------------------------------*/ -static ivas_error ivas_td_decorr_init( +static void ivas_td_decorr_init( ivas_td_decorr_state_t *hTdDecorr, const int16_t num_out_chans, const int16_t ducking_flag ) @@ -295,7 +394,7 @@ static ivas_error ivas_td_decorr_init( } } - return IVAS_ERR_OK; + return; } diff --git a/lib_com/options.h b/lib_com/options.h index 724ccb6f02de56eaae7edb43a05ff32edaf2078b..7e23e2a4a707c273b63b1ca1c428c5d2292af474 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,8 @@ #define FIX_416_ISM_BR_SWITCHING /* FhG: add missing CLDFB reconfig to ISM BR switching */ #define FIX_SP2A /* VA: Issue 412: Adjust threshold for the S_p2a feature in the tonal detector */ -#define FIX_413_SBA_DTX /*Dlb: Fix for issue 413, SBA DTX CNG in 2TC mode*/ +#define FIX_413_SBA_DTX /* Dlb: Fix for issue 413, SBA DTX CNG in 2TC mode*/ +#define FIX_417_TD_DECORR_BRATE_SW /* VA: Issue 417: fix incorrect use of TD decorrelator in bitrate switching */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 58c945b19096f0fde9c387b00bde7a670eb1845e..fc4eaf62dfb771ed4c6dac9637056cc4651510af 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1776,7 +1776,7 @@ void ivas_destroy_dec( /*-------------------------------------------------------------------* - * ivas_init_dec_get_num_cldfb_analyses() + * ivas_init_dec_get_num_cldfb_instances() * * Return number of CLDFB analysis & synthesis instances *-------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 9cadbcc4fc1b3464baeb49a21d7e1a8e2bcd1132..2c87109f6e3c28b8e70a1039b85b2deff55458f3 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1077,6 +1077,9 @@ ivas_error ivas_masa_dec_reconfigure( uint16_t *bit_stream; Decoder_State **sts; int32_t ivas_total_brate, last_ivas_total_brate; +#ifdef FIX_417_TD_DECORR_BRATE_SW + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -1084,6 +1087,10 @@ ivas_error ivas_masa_dec_reconfigure( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; +#ifdef FIX_417_TD_DECORR_BRATE_SW + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#endif + /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ @@ -1141,6 +1148,33 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * Set-up MASA coding elements and bitrates + *-----------------------------------------------------------------*/ +#endif + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp ); return error; diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 0b375d40313ef21dcd72eb81c8e64159385d74b8..59d215e22ca4abfb1e784903fc1bc055efe51da6 100755 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -131,6 +131,16 @@ ivas_error ivas_mcmasa_dec_reconfig( } else { +#ifdef FIX_417_TD_DECORR_BRATE_SW + /* if necessary, close/open td-decorrs */ + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* regularization factor is bitrate-dependent */ + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); +#else /* the decision for useTdDecorr is done in ivas_dirac_dec_init_binaural_data(). here, comparing against the same condition. */ if ( st_ivas->hDiracDecBin->useTdDecorr != ( ivas_total_brate < IVAS_48k && st_ivas->nchan_transport == 1 ) ) { @@ -141,6 +151,7 @@ ivas_error ivas_mcmasa_dec_reconfig( return error; } } +#endif } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 1ad01239cb0aadb2976d61530feff1781c83c568..4d6f8343084bf4e1dc02862741c7351cd47389c5 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -928,6 +928,8 @@ static ivas_error ivas_mc_dec_reconfig( return error; } + +#ifndef FIX_417_TD_DECORR_BRATE_SW /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ @@ -936,7 +938,7 @@ static ivas_error ivas_mc_dec_reconfig( { return error; } - +#endif /*-----------------------------------------------------------------* * Allocate the LFE handle that is coded seperately after the allocation of the core coders *-----------------------------------------------------------------*/ @@ -1121,5 +1123,28 @@ static ivas_error ivas_mc_dec_reconfig( #endif } +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + return error; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index af7281a5786c4d7f1aaeb301e61fefbcd2d43544..32a4bb58e68836f9c6dd288a0d03bb5a5b4ce9d7 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -327,6 +327,20 @@ ivas_error ivas_sba_dec_reconfigure( return error; } +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4a17c75dda9f42d5fffbded309972d8817f92ff6..3de42b0cafc88f909e6059c474986cc87142368c 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -574,7 +574,6 @@ typedef struct dirac_output_synthesis_cov_state_structure } DIRAC_OUTPUT_SYNTHESIS_COV_STATE; - /* MASA stereo transport signal type detection structure */ typedef struct { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 35819cf8cb16eb3b60e6b1e1edc8ee5d462c52f7..1fbcad6f6891e95d51d6a4edca266e395b348f3c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -52,9 +52,11 @@ * Local constants *------------------------------------------------------------------------*/ -#define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f +#define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f +#ifdef FIX_417_TD_DECORR_BRATE_SW #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#endif /* powf(0.95f, 4.0f) for sub-frame smoothing instead of CLDFB slot */ #define ADAPT_HTPROTO_IIR_FAC 0.81450625f @@ -92,7 +94,9 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); +#ifndef FIX_417_TD_DECORR_BRATE_SW static float configure_reqularization_factor( const IVAS_FORMAT ivas_format, const int32_t ivas_brate ); +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_init_binaural_data() @@ -154,6 +158,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( hBinaural->useSubframeMode = 1; +#ifndef FIX_417_TD_DECORR_BRATE_SW hBinaural->useTdDecorr = 0; if ( st_ivas->ivas_format == SBA_FORMAT ) { @@ -176,6 +181,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( hBinaural->useTdDecorr = 1; } } +#endif for ( bin = 0; bin < nBins; bin++ ) { @@ -253,6 +259,17 @@ ivas_error ivas_dirac_dec_init_binaural_data( assert( false ); } +#ifdef FIX_417_TD_DECORR_BRATE_SW + if ( hBinaural->hTdDecorr == NULL ) + { + hBinaural->useTdDecorr = 0; + } + + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hBinaural->hTdDecorr ), &( hBinaural->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( hBinaural->useTdDecorr ) { if ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_13k2 && st_ivas->ivas_format == SBA_FORMAT ) @@ -280,6 +297,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( { ivas_td_decorr_dec_close( &( hBinaural->hTdDecorr ) ); } +#endif hBinaural->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); @@ -2008,37 +2026,42 @@ static void hrtfShGetHrtf( * parametric binauralizer using IVAS codec format and current bitrate. *------------------------------------------------------------------------*/ -/*! r: Configured reqularization factor value to be set. */ -static float configure_reqularization_factor( - const IVAS_FORMAT ivas_format, /* i: IVAS codec format in use */ - const int32_t ivas_brate ) /* i: Current IVAS bitrate */ +/*! r: Configured reqularization factor value */ +#ifndef FIX_417_TD_DECORR_BRATE_SW +static +#endif + float + configure_reqularization_factor( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : IVAS total bitrate */ + ) { float reqularizationFactor; reqularizationFactor = 1.0f; /* Default value */ if ( ivas_format == MASA_FORMAT ) { - if ( ivas_brate >= IVAS_256k ) + if ( ivas_total_brate >= IVAS_256k ) { reqularizationFactor = 0.2f; } - else if ( ivas_brate == IVAS_192k ) + else if ( ivas_total_brate == IVAS_192k ) { reqularizationFactor = 0.3f; } - else if ( ivas_brate == IVAS_160k ) + else if ( ivas_total_brate == IVAS_160k ) { reqularizationFactor = 0.4f; } - else if ( ivas_brate == IVAS_128k ) + else if ( ivas_total_brate == IVAS_128k ) { reqularizationFactor = 0.5f; } - else if ( ivas_brate == IVAS_96k ) + else if ( ivas_total_brate == IVAS_96k ) { reqularizationFactor = 0.6f; } - else if ( ivas_brate >= IVAS_64k ) + else if ( ivas_total_brate >= IVAS_64k ) { reqularizationFactor = 0.8f; } @@ -2050,19 +2073,19 @@ static float configure_reqularization_factor( if ( ivas_format == MC_FORMAT ) /* This is always McMASA for parametric binauralizer. */ { - if ( ivas_brate >= IVAS_96k ) + if ( ivas_total_brate >= IVAS_96k ) { reqularizationFactor = 0.3f; } - else if ( ivas_brate >= IVAS_80k ) + else if ( ivas_total_brate >= IVAS_80k ) { reqularizationFactor = 0.5f; } - else if ( ivas_brate >= IVAS_64k ) + else if ( ivas_total_brate >= IVAS_64k ) { reqularizationFactor = 0.7f; } - else if ( ivas_brate >= IVAS_48k ) + else if ( ivas_total_brate >= IVAS_48k ) { reqularizationFactor = 0.8f; }