From 61a827020ef9170c49311882b6f10b95421c0afd Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Mon, 19 May 2025 16:54:54 +0200 Subject: [PATCH] port MR 1373 from float fixes for MC encoder crashes with br and bw switching --- lib_com/options.h | 2 ++ lib_enc/bw_detect_fx.c | 23 +++++++++++++++++++++++ lib_enc/ivas_cpe_enc_fx.c | 12 ++++++++++++ lib_enc/ivas_mct_enc_fx.c | 21 +++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 53cac6f84..dd3d2ff21 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -115,6 +115,8 @@ #define NONBE_FIX_951_MCMASA_5MS_RENDERING /* Nokia: issue #951: Differences for 5ms and 20ms rendering for McMASA at 13.2 kbps to BINAURAL */ #define NONBE_FIX_979_OSBA_STEREO_5MS /* FhG : issue #979 : 5ms and 20ms output different for OSBA and stereo */ #define FIX_983_DISC_ISM_DIGEST_NUM_OBJS /* FhG: issue #983: the discrete ISM digest function uses the wrong number of objects */ +#define FIX_ACCESS_WITHIN_NULL_STRUCT_MC_BW_SWITCHING /* FhG: fix usan error in MCT with bw swicthing */ +#define NONBE_FIX_986_MC_BW_SWITCHING /* FhG: fix crash in bw and br switching with MC */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 8a150d514..eefd5057c 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -1140,6 +1140,28 @@ Word16 set_bw_mct_fx( bw_changed = 0; move16(); +#ifdef NONBE_FIX_986_MC_BW_SWITCHING + IF( NE_16( mct_bwidth, last_mct_bwidth ) ) + { + bw_changed = 1; + move16(); + } + + /* + * always set bw for all CPEs even if it is the same value as before, + * in case of bw + br switching when changing to MCT, this overwrites + * potentially incorrect initial values + */ + FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE[cpe_id]->hCoreCoder[ch]; + st->bwidth = mct_bwidth; + move16(); + } + } +#else IF( NE_16( mct_bwidth, last_mct_bwidth ) ) { bw_changed = 1; @@ -1155,5 +1177,6 @@ Word16 set_bw_mct_fx( } } } +#endif return bw_changed; } diff --git a/lib_enc/ivas_cpe_enc_fx.c b/lib_enc/ivas_cpe_enc_fx.c index 826c23fdd..f6885dd81 100644 --- a/lib_enc/ivas_cpe_enc_fx.c +++ b/lib_enc/ivas_cpe_enc_fx.c @@ -1019,7 +1019,19 @@ ivas_error ivas_cpe_enc_fx( IF( ( NE_32( hCPE->last_element_brate, hCPE->element_brate ) || NE_16( hCPE->element_mode, hCPE->last_element_mode ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( sts[0]->bits_frame_nominal, last_bits_frame_nominal ) ) || NE_16( sts[n]->last_bwidth, sts[n]->bwidth ) ) && ( n == 0 || EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) ) { Word16 igf; +#ifdef NONBE_FIX_986_MC_BW_SWITCHING + Word16 bw; + + /* float uses ternary operator for this: bw = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? sts[n]->bwidth : sts[n]->max_bwidth; */ + bw = sts[n]->max_bwidth; + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) + { + bw = sts[n]->bwidth; + } + igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), bw, sts[n]->rf_mode ); /* Q0 */ +#else igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->rf_mode ); /* Q0 */ +#endif IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 56f5e44db..565b318f5 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -183,7 +183,9 @@ ivas_error ivas_mct_enc_fx( Word32 orig_spectrum_long_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][L_FRAME48k]; Word16 switch_bw; IVAS_FORMAT ivas_format; +#ifndef NONBE_FIX_986_MC_BW_SWITCHING Word16 max_bwidth; +#endif Word32 ivas_total_brate; ivas_error error; Word32 *pdata_fx[MAX_INPUT_CHANNELS]; @@ -198,7 +200,9 @@ ivas_error ivas_mct_enc_fx( hMCT->hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; /* pointer to write MCT side bits */ ivas_format = st_ivas->hEncoderConfig->ivas_format; +#ifndef NONBE_FIX_986_MC_BW_SWITCHING max_bwidth = st_ivas->hEncoderConfig->max_bwidth; +#endif ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; move32(); move16(); @@ -248,6 +252,22 @@ ivas_error ivas_mct_enc_fx( cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, st_ivas->nchan_transport ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) } +#ifdef NONBE_FIX_986_MC_BW_SWITCHING + IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) + { + FOR( n = 0; n < shr( hMCT->nchan_out_woLFE, 1 ); n++ ) + { + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); + } + } + ELSE + { + FOR( n = 0; n < shr( hMCT->nchan_out_woLFE, 1 ); n++ ) + { + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hCPE[0]->hCoreCoder[0]->bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, NULL, 0 ); + } + } +#else IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) { FOR( n = 0; n < shr( hMCT->nchan_out_woLFE, 1 ); n++ ) @@ -262,6 +282,7 @@ ivas_error ivas_mct_enc_fx( initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, NULL, 0 ); } } +#endif } /* set coded audio band-width */ -- GitLab