From 50e141996e586c92d2277ee282153af461a6be21 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 28 May 2025 12:24:24 +0200 Subject: [PATCH 1/2] port float MR 1501 --- lib_com/ivas_dirac_com.c | 8 ++++++-- lib_com/options.h | 1 + lib_dec/ivas_init_dec.c | 16 +++++++++++++++- lib_enc/ivas_mct_core_enc.c | 16 ++++++++++++++-- lib_enc/ivas_spar_encoder.c | 15 +++++++++++++-- 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 654640902..8f111c236 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -346,8 +346,12 @@ void ivas_get_dirac_sba_max_md_bits( /* OSBA needs an additional 2-bits safety margin to avoid acelp crashes */ if ( ivas_format == SBA_ISM_FORMAT ) { - ( *metadata_max_bits ) -= 3; - } +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + (*metadata_max_bits) -= 7; +#else + (*metadata_max_bits) -= 3; +#endif + } } else if ( sba_total_brate <= IVAS_32k ) { diff --git a/lib_com/options.h b/lib_com/options.h index 8e7f23a70..936d6c860 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -209,6 +209,7 @@ #define FIX_1003_PARAMISM_BINAURAL_RECONFIG_USAN /* FhG: fix for #1003: fix USAN caused by ParamISM reconfig */ #define FIX_1001_ARI_HM_OVERFLOW /* FhG: fix for undef behaviour in in the harmonic TCX model arithmetic coder */ #define NONBE_FIX_1005_MC_RS_TCBUFFER_UPDATE /* FhG: issue #1005: fix TC Buffer update at a MC rate switch */ +#define NONBE_FIX_SBA_SIGNALING_BITS_B /* FhG: issue 1061: option B: signal sba order additionally in OSBA */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 741a99c2a..f2f4cbdfd 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -428,22 +428,36 @@ ivas_error ivas_dec_setup( /* the number of objects is written at the end of the bitstream, in the SBA metadata */ st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; +#ifndef NONBE_FIX_SBA_SIGNALING_BITS_B if ( ivas_total_brate < IVAS_24k4 || ivas_total_brate >= IVAS_256k ) { +#endif /* read Ambisonic (SBA) planar flag */ st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_PLANAR_BITS; +#ifndef NONBE_FIX_SBA_SIGNALING_BITS_B } - +#endif + /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_ORDER_BITS; /* read Ambisonic (SBA) order */ +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + if (ivas_total_brate < IVAS_24k4) + { + st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; + st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + } +#else if ( ivas_total_brate < IVAS_256k ) { st_ivas->sba_order = 3; } +#endif if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate ) { diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index e0a643e67..81e3c2cfe 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -497,10 +497,18 @@ void ivas_mct_core_enc( { nAvailBits -= IVAS_FORMAT_SIGNALING_NBITS_EXTENDED; nAvailBits -= SBA_ORDER_BITS + SBA_PLANAR_BITS; +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + /*MCT is used at bitrates > 80 kbps and additional 1 bit is present at these bitrates*/ + if (ivas_format == SBA_ISM_FORMAT) + { + nAvailBits -= IVAS_COMBINED_FORMAT_SIGNALLING_BITS; + } +#else if ( ivas_format == SBA_ISM_FORMAT && nChannels > 4 ) { nAvailBits -= IVAS_COMBINED_FORMAT_SIGNALLING_BITS; } +#endif } for ( cpe_id = 0, i = 0; cpe_id < nCPE; cpe_id++ ) @@ -574,8 +582,12 @@ void ivas_mct_core_enc( #ifdef DEBUGGING format_bits = ( ivas_format == MC_FORMAT ? IVAS_FORMAT_SIGNALING_NBITS + MC_LS_SETUP_BITS : IVAS_FORMAT_SIGNALING_NBITS_EXTENDED + SBA_ORDER_BITS + SBA_PLANAR_BITS ); - format_bits += ( ivas_format == SBA_ISM_FORMAT && nChannels > FOA_CHANNELS ); - mct_bits += hMCT->nBitsMCT + hMCT->nchan_out_woLFE; +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + format_bits += (ivas_format == SBA_ISM_FORMAT); +#else + format_bits += (ivas_format == SBA_ISM_FORMAT && nChannels > FOA_CHANNELS); +#endif + mct_bits += hMCT->nBitsMCT + hMCT->nchan_out_woLFE; assert( ( total_brate + ( NBITS_BWIDTH + format_bits + mct_bits + sba_meta + lfe_bits ) * FRAMES_PER_SEC ) == ivas_total_brate ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index ac5611d69..c93b1382d 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -354,11 +354,22 @@ ivas_error ivas_spar_enc( /* Write SBA planar flag */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); - /* hack to indicate OSBA bitstream at VLBR */ - push_indice( st0->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); + /* hack to indicate OSBA format (SBA order = 0) at low bitrates */ + push_indice( st0->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + + /* additionally code the real SBA order */ + push_indice(st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS); +#endif + } else { +#ifdef NONBE_FIX_SBA_SIGNALING_BITS_B + /* Write SBA planar flag */ + push_indice(st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS); +#endif + /* Write SBA order */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); } -- GitLab From d48c9763d5e1beaa7649418a214e41b9fc7809c0 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 28 May 2025 12:31:49 +0200 Subject: [PATCH 2/2] fix formatting --- lib_com/ivas_dirac_com.c | 6 +++--- lib_dec/ivas_init_dec.c | 16 ++++++++-------- lib_enc/ivas_mct_core_enc.c | 16 ++++++++-------- lib_enc/ivas_spar_encoder.c | 13 ++++++------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 8f111c236..0d6f4ef61 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -347,11 +347,11 @@ void ivas_get_dirac_sba_max_md_bits( if ( ivas_format == SBA_ISM_FORMAT ) { #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - (*metadata_max_bits) -= 7; + ( *metadata_max_bits ) -= 7; #else - (*metadata_max_bits) -= 3; + ( *metadata_max_bits ) -= 3; #endif - } + } } else if ( sba_total_brate <= IVAS_32k ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f2f4cbdfd..c94dbb122 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -438,20 +438,20 @@ ivas_error ivas_dec_setup( #ifndef NONBE_FIX_SBA_SIGNALING_BITS_B } #endif - /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ + /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_ORDER_BITS; /* read Ambisonic (SBA) order */ #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - /* read the real Ambisonic order when the above bits are used to signal OSBA format */ - if (ivas_total_brate < IVAS_24k4) - { - st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; - st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; - num_bits_read += SBA_ORDER_BITS; - } + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + if ( ivas_total_brate < IVAS_24k4 ) + { + st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; + st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + } #else if ( ivas_total_brate < IVAS_256k ) { diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 81e3c2cfe..68c5c4fa4 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -498,11 +498,11 @@ void ivas_mct_core_enc( nAvailBits -= IVAS_FORMAT_SIGNALING_NBITS_EXTENDED; nAvailBits -= SBA_ORDER_BITS + SBA_PLANAR_BITS; #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - /*MCT is used at bitrates > 80 kbps and additional 1 bit is present at these bitrates*/ - if (ivas_format == SBA_ISM_FORMAT) - { - nAvailBits -= IVAS_COMBINED_FORMAT_SIGNALLING_BITS; - } + /*MCT is used at bitrates > 80 kbps and additional 1 bit is present at these bitrates*/ + if ( ivas_format == SBA_ISM_FORMAT ) + { + nAvailBits -= IVAS_COMBINED_FORMAT_SIGNALLING_BITS; + } #else if ( ivas_format == SBA_ISM_FORMAT && nChannels > 4 ) { @@ -583,11 +583,11 @@ void ivas_mct_core_enc( #ifdef DEBUGGING format_bits = ( ivas_format == MC_FORMAT ? IVAS_FORMAT_SIGNALING_NBITS + MC_LS_SETUP_BITS : IVAS_FORMAT_SIGNALING_NBITS_EXTENDED + SBA_ORDER_BITS + SBA_PLANAR_BITS ); #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - format_bits += (ivas_format == SBA_ISM_FORMAT); + format_bits += ( ivas_format == SBA_ISM_FORMAT ); #else - format_bits += (ivas_format == SBA_ISM_FORMAT && nChannels > FOA_CHANNELS); + format_bits += ( ivas_format == SBA_ISM_FORMAT && nChannels > FOA_CHANNELS ); #endif - mct_bits += hMCT->nBitsMCT + hMCT->nchan_out_woLFE; + mct_bits += hMCT->nBitsMCT + hMCT->nchan_out_woLFE; assert( ( total_brate + ( NBITS_BWIDTH + format_bits + mct_bits + sba_meta + lfe_bits ) * FRAMES_PER_SEC ) == ivas_total_brate ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index c93b1382d..661f7958a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -354,20 +354,19 @@ ivas_error ivas_spar_enc( /* Write SBA planar flag */ push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); - /* hack to indicate OSBA format (SBA order = 0) at low bitrates */ - push_indice( st0->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); + /* hack to indicate OSBA format (SBA order = 0) at low bitrates */ + push_indice( st0->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - /* additionally code the real SBA order */ - push_indice(st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS); + /* additionally code the real SBA order */ + push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); #endif - } else { #ifdef NONBE_FIX_SBA_SIGNALING_BITS_B - /* Write SBA planar flag */ - push_indice(st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS); + /* Write SBA planar flag */ + push_indice( st0->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); #endif /* Write SBA order */ -- GitLab