From eed28acdb5e3de343682cf66dddc1b9e5bf42cca Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 12 Aug 2022 09:18:47 +0200 Subject: [PATCH 01/12] Added fix FIX_I74_BW_LIMITATION to address deviation between bitrate limited BW and '-max_band' limited BW. --- lib_com/options.h | 2 ++ lib_enc/lib_enc.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index da537889ed..2d3b47ce23 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,6 +149,8 @@ #define DIRAC_DRCT_GAIN_TUNING /* issue 64: tuning of DirAC energy-compensation gains */ +#define FIX_I74_BW_LIMITATION /* Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 760ae0d353..dbca263fbd 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1572,16 +1572,26 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) { fprintf( stdout, "Switching to WB.\n" ); +#ifdef FIX_I74_BW_LIMITATION + hEncoderConfig->max_bwidth = WB; +#endif } else { fprintf( stdout, "Switching to SWB.\n" ); +#ifdef FIX_I74_BW_LIMITATION + hEncoderConfig->max_bwidth = SWB; +#endif + } } if ( hEncoderConfig->max_bwidth == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 ) { fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.", ACELP_9k60 / 1000.f ); +#ifdef FIX_I74_BW_LIMITATION + hEncoderConfig->max_bwidth = WB; +#endif } /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ @@ -1596,6 +1606,9 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f ); +#ifdef FIX_I74_BW_LIMITATION + hEncoderConfig->max_bwidth = SWB; +#endif } } -- GitLab From a579bfe20f7bae7eccc7b3216cf67e0c44153efa Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 16 Aug 2022 14:36:59 +0200 Subject: [PATCH 02/12] disable FIX_I74_BW_LIMITATION --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2d3b47ce23..083968c1e2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,7 +149,7 @@ #define DIRAC_DRCT_GAIN_TUNING /* issue 64: tuning of DirAC energy-compensation gains */ -#define FIX_I74_BW_LIMITATION /* Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ +/*#define FIX_I74_BW_LIMITATION*/ /* Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ /* ################## End DEVELOPMENT switches ######################### */ -- GitLab From 41b2da0fc4fcb6eb7687c534fed245adeb0165e4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 16 Aug 2022 14:45:12 +0200 Subject: [PATCH 03/12] [cleaning] issue 74: remove redundant function call in ivas_cpe_enc(); under FIX_I74_CLEANING --- lib_com/options.h | 4 ++-- lib_enc/ivas_cpe_enc.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 083968c1e2..97c8dfe87a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,8 +149,8 @@ #define DIRAC_DRCT_GAIN_TUNING /* issue 64: tuning of DirAC energy-compensation gains */ -/*#define FIX_I74_BW_LIMITATION*/ /* Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ - +/*#define FIX_I74_BW_LIMITATION*/ /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ +#define FIX_I74_CLEANING /* issue 74: remove redundant function call in ivas_cpe_enc() */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index f2d3241979..321ff1fdfa 100755 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -343,11 +343,13 @@ ivas_error ivas_cpe_enc( sts[0]->total_brate = ( sts[0]->bits_frame_nominal + 10 ) * FRAMES_PER_SEC; /* add small overhead; st[0]->total_brate used in coder_type_modif() */ +#ifndef FIX_I74_CLEANING if ( ( sts[0]->last_bwidth < max_bwidth ) || ( sts[0]->last_core_brate <= SID_2k40 ) ) /* IVAS_fmToDo: TBV - BWD output is not known here yet !!! */ { /* reconfigure in case of BW switching or if last frame was a SID/NO_DATA with coarse partitioning */ hCPE->hStereoDft->nbands = stereo_dft_band_config( hCPE->hStereoDft->band_limits, hCPE->hStereoDft->hConfig->band_res, hCPE->hStereoDft->NFFT, ENC ); } +#endif /* Update DFT Stereo memories */ stereo_dft_enc_update( hCPE->hStereoDft, sts[0]->max_bwidth -- GitLab From 7df47684ab46abb18c83f32a2c03942ff628744d Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 18 Aug 2022 10:55:42 +0200 Subject: [PATCH 04/12] alternative patch within FIX_I74_BW_LIMITATION_ALT: sanitize the bandwidth before entering the encoding function --- lib_com/options.h | 1 + lib_enc/ivas_stat_enc.h | 3 ++ lib_enc/lib_enc.c | 106 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 97c8dfe87a..b1f230a73a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,6 +150,7 @@ #define DIRAC_DRCT_GAIN_TUNING /* issue 64: tuning of DirAC energy-compensation gains */ /*#define FIX_I74_BW_LIMITATION*/ /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ +#define FIX_I74_BW_LIMITATION_ALT /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate; alternative fix */ #define FIX_I74_CLEANING /* issue 74: remove redundant function call in ivas_cpe_enc() */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 331e1a75e7..151efe2c09 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -989,6 +989,9 @@ typedef struct encoder_config_structure int32_t input_Fs; /* input signal sampling frequency in Hz */ int16_t nchan_inp; /* number of input audio channels */ int16_t max_bwidth; /* maximum encoded bandwidth */ +#ifdef FIX_I74_BW_LIMITATION_ALT + int16_t max_bwidth_api; /* maximum encoded bandwidth, as set on API level */ +#endif IVAS_FORMAT ivas_format; /* IVAS format */ int16_t element_mode_init; /* element mode used at initialization */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index dbca263fbd..76832e7b0a 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -78,6 +78,7 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); static void updateBandwidthFromFs( const ENCODER_CONFIG_HANDLE hEncoderConfig ); +static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); @@ -1025,6 +1026,13 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { for ( i = 0; i < hEncoderConfig->nchan_inp; ++i ) @@ -1844,6 +1852,100 @@ static void updateBandwidthFromFs( } +#ifdef FIX_I74_BW_LIMITATION_ALT +/*---------------------------------------------------------------------* + * sanitizeBandwidth() + * + * + *---------------------------------------------------------------------*/ +static ivas_error sanitizeBandwidth( + const IVAS_ENC_HANDLE hIvasEnc ) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + int16_t max_bwidth_tmp; + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + max_bwidth_tmp = hEncoderConfig->max_bwidth_api; + + /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ + if ( hEncoderConfig->input_Fs == 8000 && max_bwidth_tmp > NB ) + { + max_bwidth_tmp = NB; + } + else if ( hEncoderConfig->input_Fs == 16000 && max_bwidth_tmp > WB ) + { + max_bwidth_tmp = WB; + } + else if ( hEncoderConfig->input_Fs == 32000 && max_bwidth_tmp > SWB ) + { + max_bwidth_tmp = SWB; + } + + /* NB coding not supported in IVAS. Switching to WB. */ + if ( max_bwidth_tmp == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) + { + if ( hEncoderConfig->input_Fs >= 16000 ) + { + max_bwidth_tmp = WB; + } + else + { + return IVAS_ERR_INVALID_BITRATE; + } + } + + if ( hEncoderConfig->ivas_format == MONO_FORMAT ) + { + if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 ) + { + if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) + { + max_bwidth_tmp = WB; + } + else + { + max_bwidth_tmp = SWB; + } + } + + if ( max_bwidth_tmp == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 ) + { + max_bwidth_tmp = WB; + } + + /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ + if ( ( max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) + { + if ( hEncoderConfig->input_Fs >= 16000 ) + { + max_bwidth_tmp = WB; + } + else + { + return IVAS_ERR_INVALID_BITRATE; + } + } + } + else + { + if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) + { + max_bwidth_tmp = SWB; + } + } + + if ( hEncoderConfig->max_bwidth != max_bwidth_tmp ) + { + hEncoderConfig->max_bwidth = max_bwidth_tmp; + hIvasEnc->switchingActive = true; + } + + return IVAS_ERR_OK; +} +#endif + + /*---------------------------------------------------------------------* * setBandwidth() * @@ -1866,6 +1968,10 @@ static ivas_error setBandwidth( return error; } +#ifdef FIX_I74_BW_LIMITATION_ALT + hEncoderConfig->max_bwidth_api = newBandwidth; +#endif + /* NB coding not supported in IVAS. Switching to WB. */ if ( newBandwidth == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) { -- GitLab From 55a760d31f1380395d36a45c0ef474db2a81cb5e Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 18 Aug 2022 12:33:50 +0200 Subject: [PATCH 05/12] Remove obsolete initial fix FIX_I74_BW_LIMITATION --- lib_com/options.h | 1 - lib_enc/lib_enc.c | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index b1f230a73a..da7ed8d239 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -149,7 +149,6 @@ #define DIRAC_DRCT_GAIN_TUNING /* issue 64: tuning of DirAC energy-compensation gains */ -/*#define FIX_I74_BW_LIMITATION*/ /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate */ #define FIX_I74_BW_LIMITATION_ALT /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate; alternative fix */ #define FIX_I74_CLEANING /* issue 74: remove redundant function call in ivas_cpe_enc() */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 76832e7b0a..0af18e48d4 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1580,26 +1580,16 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) { fprintf( stdout, "Switching to WB.\n" ); -#ifdef FIX_I74_BW_LIMITATION - hEncoderConfig->max_bwidth = WB; -#endif } else { fprintf( stdout, "Switching to SWB.\n" ); -#ifdef FIX_I74_BW_LIMITATION - hEncoderConfig->max_bwidth = SWB; -#endif - } } if ( hEncoderConfig->max_bwidth == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 ) { fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.", ACELP_9k60 / 1000.f ); -#ifdef FIX_I74_BW_LIMITATION - hEncoderConfig->max_bwidth = WB; -#endif } /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ @@ -1614,9 +1604,6 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f ); -#ifdef FIX_I74_BW_LIMITATION - hEncoderConfig->max_bwidth = SWB; -#endif } } -- GitLab From fa408b98071c68974b1202c7003d1da8f7b13bab Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 23 Aug 2022 13:46:28 +0200 Subject: [PATCH 06/12] move max_bwidth_api from encoder_config_struct to IVAS_ENC-struct, rename to newBandwidthApi --- lib_enc/ivas_stat_enc.h | 3 --- lib_enc/lib_enc.c | 7 +++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 151efe2c09..331e1a75e7 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -989,9 +989,6 @@ typedef struct encoder_config_structure int32_t input_Fs; /* input signal sampling frequency in Hz */ int16_t nchan_inp; /* number of input audio channels */ int16_t max_bwidth; /* maximum encoded bandwidth */ -#ifdef FIX_I74_BW_LIMITATION_ALT - int16_t max_bwidth_api; /* maximum encoded bandwidth, as set on API level */ -#endif IVAS_FORMAT ivas_format; /* IVAS format */ int16_t element_mode_init; /* element mode used at initialization */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 0af18e48d4..2890ae5c73 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -64,6 +64,9 @@ struct IVAS_ENC int16_t rf_fec_offset_loc; bool ismMetadataProvided[MAX_NUM_OBJECTS]; bool maxBandwidthUser; /* Was a specific max bandwith selected by the user? */ +#ifdef FIX_I74_BW_LIMITATION_ALT + IVAS_ENC_BANDWIDTH newBandwidthApi; /* maximum encoded bandwidth, as set on API level */ +#endif }; /*---------------------------------------------------------------------* @@ -1853,7 +1856,7 @@ static ivas_error sanitizeBandwidth( hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - max_bwidth_tmp = hEncoderConfig->max_bwidth_api; + max_bwidth_tmp = hIvasEnc->newBandwidthApi; /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */ if ( hEncoderConfig->input_Fs == 8000 && max_bwidth_tmp > NB ) @@ -1956,7 +1959,7 @@ static ivas_error setBandwidth( } #ifdef FIX_I74_BW_LIMITATION_ALT - hEncoderConfig->max_bwidth_api = newBandwidth; + hIvasEnc->newBandwidthApi = newBandwidth; #endif /* NB coding not supported in IVAS. Switching to WB. */ -- GitLab From 4ce71960cf3a85ae7ecfd4dbe5de977e7c68df5a Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 29 Aug 2022 16:40:36 +0200 Subject: [PATCH 07/12] FIX_I74_BW_LIMITATION_ALT: no need for updateBandwidthFromFs() anymore --- lib_enc/lib_enc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 2890ae5c73..8bae7b8fa7 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -80,7 +80,9 @@ static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_EN static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); +#ifndef FIX_I74_BW_LIMITATION_ALT static void updateBandwidthFromFs( const ENCODER_CONFIG_HANDLE hEncoderConfig ); +#endif static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); @@ -826,7 +828,9 @@ static ivas_error configureEncoder( hEncoderConfig->input_Fs = inputFs; +#ifndef FIX_I74_BW_LIMITATION_ALT updateBandwidthFromFs( hEncoderConfig ); +#endif /*-----------------------------------------------------------------* * Channel-aware mode @@ -1814,7 +1818,7 @@ static ivas_error doCommonSetterChecks( return IVAS_ERR_OK; } - +#ifndef FIX_I74_BW_LIMITATION_ALT /*---------------------------------------------------------------------* * updateBandwidthFromFs() * @@ -1840,7 +1844,7 @@ static void updateBandwidthFromFs( return; } - +#endif #ifdef FIX_I74_BW_LIMITATION_ALT /*---------------------------------------------------------------------* @@ -1974,12 +1978,14 @@ static ivas_error setBandwidth( hIvasEnc->switchingActive = true; } +#ifndef FIX_I74_BW_LIMITATION_ALT /* Limit bandwidth to half of sampling rate - only possible if * sampling rate has already been set via configure function */ if ( hIvasEnc->isConfigured ) { updateBandwidthFromFs( hIvasEnc->st_ivas->hEncoderConfig ); } +#endif return IVAS_ERR_OK; } -- GitLab From f5fb28cebf8a673286f7af8dc47971e19cbdd461 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 2 Sep 2022 13:13:26 +0200 Subject: [PATCH 08/12] call sanitizeBandwidth() also in front of ivas_init_encoder() --- lib_enc/lib_enc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 85ad2a5526..345053eefc 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -890,6 +890,13 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + /*-----------------------------------------------------------------* * Finalize initialization *-----------------------------------------------------------------*/ -- GitLab From ea5ce9b0e07428cfd631eed7778fca00528cec97 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Sep 2022 18:55:14 +0200 Subject: [PATCH 09/12] reintroduce warning print-out that bandwidth was reduced automatically due to bitrate; also remove redundant printout of "Bandwidth limited to XX." as the same info is already present in "Max. encoded bandwidth: XX"; changes are under FIX_I74_BW_LIMITATION_ALT --- lib_enc/lib_enc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 345053eefc..704121b563 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1413,7 +1413,9 @@ static ivas_error printConfigInfo_enc( { Encoder_Struct *st_ivas; ENCODER_CONFIG_HANDLE hEncoderConfig; +#ifndef FIX_I74_BW_LIMITATION_ALT char max_bwidth_string[4]; +#endif st_ivas = hIvasEnc->st_ivas; hEncoderConfig = st_ivas->hEncoderConfig; @@ -1554,6 +1556,7 @@ static ivas_error printConfigInfo_enc( * Print potential limitation of audio bandwidth *-----------------------------------------------------------------*/ +#ifndef FIX_I74_BW_LIMITATION_ALT switch ( hEncoderConfig->max_bwidth ) { case NB: @@ -1569,19 +1572,43 @@ static ivas_error printConfigInfo_enc( strncpy( max_bwidth_string, "FB\0", sizeof( max_bwidth_string ) ); break; } +#endif if ( st_ivas->hEncoderConfig->Opt_SC_VBR && !hEncoderConfig->Opt_DTX_ON ) { return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "\nError: SC-VBR 5900 bps not supported without DTX\n\n" ); } +#ifndef FIX_I74_BW_LIMITATION_ALT if ( hIvasEnc->maxBandwidthUser ) { fprintf( stdout, "\nBandwidth limited to %s.\n", max_bwidth_string ); } +#endif if ( hEncoderConfig->ivas_format == MONO_FORMAT ) { +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( hIvasEnc->newBandwidthApi != hEncoderConfig->max_bwidth ) + { + if ( hIvasEnc->newBandwidthApi == FB ) + { + fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f ); + if ( hEncoderConfig->max_bwidth == WB ) + { + fprintf( stdout, "Switching to WB.\n" ); + } + else + { + fprintf( stdout, "Switching to SWB.\n" ); + } + } + else if ( hIvasEnc->newBandwidthApi == SWB ) + { + fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.\n", ACELP_9k60 / 1000.f ); + } + } +#else if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f ); @@ -1599,9 +1626,14 @@ static ivas_error printConfigInfo_enc( { fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.", ACELP_9k60 / 1000.f ); } +#endif /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( ( hIvasEnc->newBandwidthApi == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) +#else if ( ( hEncoderConfig->max_bwidth == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) +#endif { fprintf( stdout, "\nError: Unsupported mode NB %d bps, NB mode supports rates 5900-24400 bps\n\n", hEncoderConfig->ivas_total_brate ); return IVAS_ERR_INVALID_BITRATE; @@ -1609,7 +1641,11 @@ static ivas_error printConfigInfo_enc( } else { +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( hIvasEnc->newBandwidthApi != hEncoderConfig->max_bwidth ) +#else if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) +#endif { fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f ); } -- GitLab From 883bc1c984b92eeb695840bbf30f3ea594c39010 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Sep 2022 19:06:17 +0200 Subject: [PATCH 10/12] fix Linux builds --- lib_enc/lib_enc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 704121b563..ab34209495 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1415,6 +1415,9 @@ static ivas_error printConfigInfo_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; #ifndef FIX_I74_BW_LIMITATION_ALT char max_bwidth_string[4]; +#else + int16_t newBandwidthApi; + ivas_error error; #endif st_ivas = hIvasEnc->st_ivas; @@ -1556,7 +1559,12 @@ static ivas_error printConfigInfo_enc( * Print potential limitation of audio bandwidth *-----------------------------------------------------------------*/ -#ifndef FIX_I74_BW_LIMITATION_ALT +#ifdef FIX_I74_BW_LIMITATION_ALT + if ( ( error = bandwidthApiToInternal( hIvasEnc->newBandwidthApi, &newBandwidthApi ) ) != IVAS_ERR_OK ) + { + return error; + } +#else switch ( hEncoderConfig->max_bwidth ) { case NB: @@ -1589,9 +1597,9 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->ivas_format == MONO_FORMAT ) { #ifdef FIX_I74_BW_LIMITATION_ALT - if ( hIvasEnc->newBandwidthApi != hEncoderConfig->max_bwidth ) + if ( newBandwidthApi != hEncoderConfig->max_bwidth ) { - if ( hIvasEnc->newBandwidthApi == FB ) + if ( newBandwidthApi == FB ) { fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f ); if ( hEncoderConfig->max_bwidth == WB ) @@ -1630,7 +1638,7 @@ static ivas_error printConfigInfo_enc( /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ #ifdef FIX_I74_BW_LIMITATION_ALT - if ( ( hIvasEnc->newBandwidthApi == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) + if ( ( newBandwidthApi == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) #else if ( ( hEncoderConfig->max_bwidth == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) #endif -- GitLab From 35303c95a94298a1c1d54d42690949006237a737 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Sep 2022 19:13:14 +0200 Subject: [PATCH 11/12] fix Linux builds --- lib_enc/lib_enc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index ab34209495..5651e1e962 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1611,7 +1611,7 @@ static ivas_error printConfigInfo_enc( fprintf( stdout, "Switching to SWB.\n" ); } } - else if ( hIvasEnc->newBandwidthApi == SWB ) + else if ( newBandwidthApi == SWB ) { fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.\n", ACELP_9k60 / 1000.f ); } @@ -1650,7 +1650,7 @@ static ivas_error printConfigInfo_enc( else { #ifdef FIX_I74_BW_LIMITATION_ALT - if ( hIvasEnc->newBandwidthApi != hEncoderConfig->max_bwidth ) + if ( newBandwidthApi != hEncoderConfig->max_bwidth ) #else if ( hEncoderConfig->max_bwidth == FB && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) #endif -- GitLab From 6192e299d54f6053c7069e2052b298e9abde7f6c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 21 Sep 2022 18:45:24 +0200 Subject: [PATCH 12/12] temporary fix to keep EVS bit-exactness --- lib_enc/lib_enc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 9420d47a07..ede42ddeaf 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1950,6 +1950,7 @@ static ivas_error sanitizeBandwidth( if ( hEncoderConfig->ivas_format == MONO_FORMAT ) { +#if 0 // IVAS_fmToDo: temporary disabled to keep EVS bit-exactness -> to be verified if ( max_bwidth_tmp == FB && hEncoderConfig->ivas_total_brate < ACELP_16k40 ) { if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) @@ -1966,6 +1967,7 @@ static ivas_error sanitizeBandwidth( { max_bwidth_tmp = WB; } +#endif /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ if ( ( max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) -- GitLab