From dc1ecdb5fd5d0ec9e0267c63e366ddd232e1fd13 Mon Sep 17 00:00:00 2001 From: "@ragot" Date: Fri, 26 May 2023 12:14:33 +0200 Subject: [PATCH 1/6] initial support of -binaural command line option --- apps/encoder.c | 32 ++++++++++++++++++++++++++++++++ lib_com/options.h | 1 + lib_enc/ivas_stat_enc.h | 3 +++ lib_enc/lib_enc.c | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index df7c0915d4..332d7f8c27 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -98,6 +98,9 @@ typedef struct char *outputBitstreamFilename; int32_t inputFs; IVAS_ENC_INPUT_FORMAT inputFormat; +#ifdef BINAURAL_AUDIO_CMDLINE + bool is_binaural; +#endif EncInputFormatConfig inputFormatConfig; bool max_bwidth_user; IVAS_ENC_BANDWIDTH maxBandwidth; @@ -362,17 +365,29 @@ int main( switch ( arg.inputFormat ) { case IVAS_ENC_INPUT_MONO: +#ifdef BINAURAL_AUDIO_CMDLINE + if ( ( error = IVAS_ENC_ConfigureForMono( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, caConfig, arg.inputFormatConfig.stereoToMonoDownmix, arg.is_binaural ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_ENC_ConfigureForMono( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, caConfig, arg.inputFormatConfig.stereoToMonoDownmix ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_ENC_ConfigureForMono failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); goto cleanup; } break; case IVAS_ENC_INPUT_STEREO: +#ifdef BINAURAL_AUDIO_CMDLINE +#ifdef DEBUGGING + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural, arg.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.is_binaural ) ) != IVAS_ERR_OK ) +#endif +#else #ifdef DEBUGGING if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig, arg.inputFormatConfig.stereoMode ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_ENC_ConfigureForStereo( hIvasEnc, arg.inputFs, totalBitrate, arg.max_bwidth_user, bandwidth, arg.dtxConfig ) ) != IVAS_ERR_OK ) +#endif #endif { fprintf( stderr, "\nIVAS_ENC_ConfigureForStereo failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); @@ -865,6 +880,9 @@ static void initArgStruct( EncArguments *arg ) arg->outputBitstreamFilename = NULL; arg->inputFs = 0; arg->inputFormat = IVAS_ENC_INPUT_MONO; +#ifdef BINAURAL_AUDIO_CMDLINE + arg->is_binaural = false; +#endif arg->inputFormatConfig.stereoToMonoDownmix = false; arg->max_bwidth_user = false; arg->maxBandwidth = IVAS_ENC_BANDWIDTH_UNDEFINED; @@ -1207,6 +1225,16 @@ static bool parseCmdlIVAS_enc( * IVAS Formats *-----------------------------------------------------------------*/ +#ifdef BINAURAL_AUDIO_CMDLINE + else if ( strcmp( argv_to_upper, "-BINAURAL" ) == 0 ) + { + i++; + if ( strcmp( argv_to_upper, "-BINAURAL" ) == 0 ) + { + arg->is_binaural = true; + } + } +#endif else if ( strcmp( argv_to_upper, "-STEREO" ) == 0 ) { i++; @@ -1487,6 +1515,7 @@ static bool parseCmdlIVAS_enc( { arg->inputFormat = IVAS_ENC_INPUT_MONO; arg->inputFormatConfig.stereoToMonoDownmix = true; + i++; } else if ( strcmp( argv_to_upper, "-BYPASS" ) == 0 ) // VE: should be renamed to "-pca" @@ -1674,6 +1703,9 @@ static void usage_enc( void ) fprintf( stdout, "Options:\n" ); fprintf( stdout, "--------\n" ); fprintf( stdout, "EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -masa, -mc\n" ); +#ifdef BINAURAL_AUDIO_CMDLINE + fprintf( stdout, "-binaural : Optional indication that input is binaural audio (to be used with -stereo or -stereo_dmx_evs)\n" ); +#endif fprintf( stdout, "-stereo : Stereo format \n" ); fprintf( stdout, "-ism (+)Ch Files : ISM format \n" ); fprintf( stdout, " where Ch specifies the number of ISMs (1-4)\n" ); diff --git a/lib_com/options.h b/lib_com/options.h index 72332841b3..afaf5e1cd3 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -218,6 +218,7 @@ #define FIX_481_UNUSED_VARIABLES /* Nokia: Fix issue #481: Unused debug variables */ +#define BINAURAL_AUDIO_CMDLINE /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 806899c343..71e4c85c27 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1048,6 +1048,9 @@ typedef struct encoder_config_structure int16_t nchan_inp; /* number of input audio channels */ int16_t max_bwidth; /* maximum encoded bandwidth */ IVAS_FORMAT ivas_format; /* IVAS format */ +#ifdef BINAURAL_AUDIO_CMDLINE + bool is_binaural; /* flag indicating if input is binaural audio */ +#endif int16_t element_mode_init; /* element mode used at initialization */ int16_t stereo_dmx_evs; /* flag to indicate that stereo downmix for EVS encoder */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 2e56f384ec..fa801f67ad 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -267,7 +267,12 @@ ivas_error IVAS_ENC_ConfigureForMono( const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig, /* i : configuration of channel-aware mode, can by set to default by using IVAS_ENC_GetDefaultChannelAwareConfig() */ - const bool downmixFromStereo /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */ +#ifdef BINAURAL_AUDIO_CMDLINE + const bool downmixFromStereo, /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */ + const bool is_binaural /* i : if true, the input is binaural audio */ +#else + const bool downmixFromStereo /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */ +#endif ) { ivas_error error; @@ -280,6 +285,9 @@ ivas_error IVAS_ENC_ConfigureForMono( } hIvasEnc->st_ivas->hEncoderConfig->ivas_format = MONO_FORMAT; +#ifdef BINAURAL_AUDIO_CMDLINE + hIvasEnc->st_ivas->hEncoderConfig->is_binaural = is_binaural; +#endif if ( downmixFromStereo ) { @@ -305,7 +313,12 @@ ivas_error IVAS_ENC_ConfigureForStereo( const int32_t bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ - const IVAS_ENC_DTX_CONFIG dtxConfig /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ +#ifdef BINAURAL_AUDIO_CMDLINE + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const bool is_binaural /* i : flag indicating if input is binaural audio */ +#else + const IVAS_ENC_DTX_CONFIG dtxConfig /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ +#endif #ifdef DEBUGGING , const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */ @@ -326,6 +339,9 @@ ivas_error IVAS_ENC_ConfigureForStereo( hEncoderConfig = st_ivas->hEncoderConfig; hEncoderConfig->nchan_inp = 2; hEncoderConfig->ivas_format = STEREO_FORMAT; +#ifdef BINAURAL_AUDIO_CMDLINE + hEncoderConfig->is_binaural = is_binaural; +#endif #ifdef DEBUGGING switch ( stereoMode ) @@ -1528,6 +1544,12 @@ static ivas_error printConfigInfo_enc( if ( hEncoderConfig->stereo_dmx_evs ) { fprintf( stdout, "IVAS format: stereo downmix to bit-exact EVS mono\n" ); +#ifdef BINAURAL_AUDIO_CMDLINE + if ( hEncoderConfig->is_binaural ) + { + fprintf( stdout, "Optional indication: binaural audio\n" ); + } +#endif } else { @@ -1562,6 +1584,12 @@ static ivas_error printConfigInfo_enc( { fprintf( stdout, "IVAS format: stereo - MDCT stereo\n" ); } +#endif +#ifdef BINAURAL_AUDIO_CMDLINE + if ( hEncoderConfig->is_binaural ) + { + fprintf( stdout, "Optional indication: binaural audio\n" ); + } #endif } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) -- GitLab From 28d098455a2456bd847111cc512b1a7bf05f9196 Mon Sep 17 00:00:00 2001 From: "@ragot" Date: Fri, 26 May 2023 12:49:32 +0200 Subject: [PATCH 2/6] propagating is_binaural as extra information for stereo dmx; for stereo is_binaural is available in st_ivas->hEncoderConfig so no extra change required --- lib_com/ivas_prot.h | 5 +++++ lib_enc/ivas_stereo_dmx_evs.c | 7 ++++++- lib_enc/lib_enc.c | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 556daf327b..c5c5138a83 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -61,7 +61,12 @@ void stereo_dmx_evs_enc( STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ int16_t data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal */ +#ifdef BINAURAL_AUDIO_CMDLINE + const int16_t n_samples, /* i : number of input samples */ + const bool is_binaural /* i : indication that input is binaural audio */ +#else const int16_t n_samples /* i : number of input samples */ +#endif ); /*! r: number of channels to be analysed */ diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index a5c0fe147f..e772365a8c 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -788,7 +788,12 @@ void stereo_dmx_evs_enc( STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS, /* i/o: Stereo downmix for EVS encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ int16_t data[CPE_CHANNELS * L_FRAME48k], /* i/o: input signal */ - const int16_t n_samples /* i : number of input samples */ +#ifdef BINAURAL_AUDIO_CMDLINE + const int16_t n_samples, /* i : number of input samples */ + const bool is_binaural /* i : indication that input is binaural audio */ +#else + const int16_t n_samples /* i : number of input samples */ +#endif ) { int16_t n; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index fa801f67ad..9d381913ad 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1261,7 +1261,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( if ( hEncoderConfig->stereo_dmx_evs == 1 ) { inputBufferSize /= 2; +#ifdef BINAURAL_AUDIO_CMDLINE + stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural); +#else stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize ); +#endif } if ( hEncoderConfig->Opt_AMR_WB ) -- GitLab From 43f2982d939d83ea7f69639c063c2c5501f18c16 Mon Sep 17 00:00:00 2001 From: "@ragot" Date: Sat, 3 Jun 2023 01:00:27 +0200 Subject: [PATCH 3/6] fix clang issue --- lib_enc/lib_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 9d381913ad..dc142eb7a1 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1262,7 +1262,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( { inputBufferSize /= 2; #ifdef BINAURAL_AUDIO_CMDLINE - stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural); + stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); #else stereo_dmx_evs_enc( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize ); #endif -- GitLab From 0b637afc7d1f7de0e5a1044dfb40f76644a825d4 Mon Sep 17 00:00:00 2001 From: ragot Date: Sat, 3 Jun 2023 01:33:55 +0200 Subject: [PATCH 4/6] fix declaration issue --- lib_enc/lib_enc.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index a4a3726b45..8d8ede4d77 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -161,8 +161,13 @@ ivas_error IVAS_ENC_ConfigureForMono( const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig, /* i : configuration of channel-aware mode, can by set to default by using IVAS_ENC_GetDefaultChannelAwareConfig() */ + const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig, /* i : configuration of channel-aware mode, can by set to default by using IVAS_ENC_GetDefaultChannelAwareConfig() */ +#ifdef BINAURAL_AUDIO_CMDLINE + const bool downmixFromStereo, /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */ + const bool is_binaural /* i : if true, the input is binaural audio */ +#else const bool downmixFromStereo /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */ +#endif ); /*! r: error code */ @@ -172,10 +177,15 @@ ivas_error IVAS_ENC_ConfigureForStereo( const int32_t bitrate, /* i : requested bitrate of the output bitstream */ const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */ const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ +#ifdef BINAURAL_AUDIO_CMDLINE + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const bool is_binaural /* i : flag indicating if input is binaural audio */ +#else const IVAS_ENC_DTX_CONFIG dtxConfig /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ +#endif #ifdef DEBUGGING , - const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */ + const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */ #endif ); -- GitLab From a107d305eab0df4dc1745bc9ef119ee8c348e76c Mon Sep 17 00:00:00 2001 From: ragot Date: Sat, 3 Jun 2023 01:46:09 +0200 Subject: [PATCH 5/6] fix warning --- lib_enc/ivas_stereo_dmx_evs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 6ebf0ce8fc..8dd0db99e3 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -1163,6 +1163,13 @@ void stereo_dmx_evs_enc( int16_t input_frame; +#ifdef BINAURAL_AUDIO_CMDLINE + if (is_binaural) + { + /* use of is_binaural flag is to be considered */ + } +#endif + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); for ( n = 0; n < input_frame; n++ ) -- GitLab From 9b967796503c82bf7f128fff5e9802dec5d640ac Mon Sep 17 00:00:00 2001 From: ragot Date: Sat, 3 Jun 2023 01:57:45 +0200 Subject: [PATCH 6/6] fix clang --- lib_enc/ivas_stereo_dmx_evs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 8dd0db99e3..e479e28cdb 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -1164,7 +1164,7 @@ void stereo_dmx_evs_enc( int16_t input_frame; #ifdef BINAURAL_AUDIO_CMDLINE - if (is_binaural) + if ( is_binaural ) { /* use of is_binaural flag is to be considered */ } -- GitLab