From 9614da8326b8b5ba0a083d7b47d2622311d28912 Mon Sep 17 00:00:00 2001 From: Stefan Bayer Date: Thu, 23 May 2024 12:10:26 +0200 Subject: [PATCH 1/3] fix for #1105, fix snapping to renderer time resolution borders in the time scale modification in silence portions --- apps/decoder.c | 17 +++++++++++++++++ lib_com/options.h | 1 + lib_dec/jbm_pcmdsp_apa.c | 25 ++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9d38acb1da..f857e0b1d0 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2389,7 +2389,11 @@ static ivas_error decodeG192( { int16_t maxScaling; /* max scaling as abs diff to the normal frame size in samples */ +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + maxScaling = arg.tsmScale >= 100 ? nOutSamples * vec_pos_len : 0; /* always allow the maximum possible scaling */ +#else maxScaling = (int16_t) ceilf( (float) abs( arg.tsmScale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) ); +#endif if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); @@ -2589,6 +2593,19 @@ static ivas_error decodeG192( goto cleanup; } } +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + else if ( arg.tsmEnabled ) + { + int16_t maxScaling; + /* max scaling as abs diff to the normal frame size in samples */ + maxScaling = arg.tsmScale >= 100 ? nOutSamples * vec_pos_len : 0; /* always allow the maximum possible scaling */ + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#endif #endif #endif if ( ( error = BS_Reader_ReadFrame_short( hBsReader, bit_stream, &num_bits, &bfi ) ) != IVAS_ERR_OK ) diff --git a/lib_com/options.h b/lib_com/options.h index 6c4363df17..eae2486b8d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -190,6 +190,7 @@ #define NONBE_FIX_1087_OOB_SBA_DTX_RS /* VA: issue 1087: Extend the length of the buffer for MCT decoding to avoid out-of-bound writing in SBA SID bitrate switching decoding */ #define NONBE_FIX_1091_PMC_LOW_SIGNAL_BURSTS /* FhG: fix for #1091, fix limit calculation for the regularized inverse of Kx to avoid bursts in very low signals */ #define NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR /* Nok: issue 1074 fixing number of objects signaling in OMASA low rate */ +#define NONBE_FIX_1105_TSM_IN_SILENCE /* FhG: fix for issue #1105: align code to the specification text */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index bf58f0fa1e..032fa0dae7 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -1163,17 +1163,34 @@ static bool shrink_frm( quality = 5; if ( ps->evs_compat_mode == false ) { - +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + if ( maxScaling != 0U && s_end > maxScaling + 1 ) + { + xtract = maxScaling; + } + else + { + /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ + xtract = s_end; + } + /* snap to renderer time slot borders */ + xtract += ( ps->l_ts - xtract % ps->l_ts ) % ps->l_ts - ( ps->l_ts - ps->l_r_buf ) % ps->l_ts; +#else xtract = maxScaling; /* take samples already in the renderer buf into account */ xtract += ps->l_r_buf; /* snap to renderer time slot borders */ xtract -= ( ps->l_ts - ( l_frm - xtract + ps->l_r_buf ) % ps->l_ts ); +#endif while ( xtract < 0 ) { xtract += ps->l_ts; } +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + while ( xtract > ( s_end ) ) +#else while ( xtract > ( s_end - ps->num_channels ) ) +#endif { /* exceeded the possible shrinking, go back one renderer ts*/ xtract -= ps->l_ts; @@ -1398,10 +1415,16 @@ static bool extend_frm( xtract[n] = s_start + ps->num_channels; if ( ps->evs_compat_mode == false ) { +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + xtract[n] -= ps->num_channels; + /* take renderer buffer samples into accout */ + xtract[n] += ( ps->l_r_buf % ps->l_ts ); +#else /* take renderer buffer samples into accout */ xtract[n] += ps->l_r_buf; /* snap to next renderer time slot border to resynchronize */ xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; +#endif } } else -- GitLab From 719d11f2c75b71070dcdae740ede3cf06d6219ea Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 5 Jun 2024 10:57:32 +0200 Subject: [PATCH 2/3] allow max scaling in tsm scale file part as well --- apps/decoder.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/decoder.c b/apps/decoder.c index f857e0b1d0..8f049ab95b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2586,7 +2586,11 @@ static ivas_error decodeG192( } int16_t maxScaling; /* max scaling as abs diff to the normal frame size in samples */ +#ifdef NONBE_FIX_1105_TSM_IN_SILENCE + maxScaling = arg.tsmScale >= 100 ? nOutSamples * vec_pos_len : 0; /* always allow the maximum possible scaling */ +#else maxScaling = (int16_t) ceilf( (float) abs( arg.tsmScale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) ); +#endif if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); -- GitLab From c1d575f1fd5e7e2501e11287d18381995f6d8931 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Wed, 5 Jun 2024 11:13:31 +0200 Subject: [PATCH 3/3] actually use value read from scale file --- apps/decoder.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 8f049ab95b..2cf649471b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2587,11 +2587,11 @@ static ivas_error decodeG192( int16_t maxScaling; /* max scaling as abs diff to the normal frame size in samples */ #ifdef NONBE_FIX_1105_TSM_IN_SILENCE - maxScaling = arg.tsmScale >= 100 ? nOutSamples * vec_pos_len : 0; /* always allow the maximum possible scaling */ + maxScaling = scale >= 100 ? nOutSamples * vec_pos_len : 0; /* always allow the maximum possible scaling */ #else - maxScaling = (int16_t) ceilf( (float) abs( arg.tsmScale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) ); + maxScaling = (int16_t) ceilf( (float) abs( scale - 100 ) / 100.0f * (float) ( nOutSamples * vec_pos_len ) ); #endif - if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, arg.tsmScale ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, maxScaling, scale ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_VoIP_SetScale failed: %s \n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; -- GitLab