From 3447d9da1e7f4b8f175dfba8f4550dcd58c0e586 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 15 Mar 2024 16:55:44 +0100 Subject: [PATCH 001/102] add conversion functions for ambisonics input/output --- Workspace_msvc/lib_util.vcxproj | 2 + lib_util/ambi_cenvert.c | 90 +++++++++++++++++++++++++++++++++ lib_util/ambi_convert.h | 66 ++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 lib_util/ambi_cenvert.c create mode 100644 lib_util/ambi_convert.h diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 80e744c4f1..bd70056f36 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -100,6 +100,7 @@ + @@ -126,6 +127,7 @@ + diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c new file mode 100644 index 0000000000..711baba8d5 --- /dev/null +++ b/lib_util/ambi_cenvert.c @@ -0,0 +1,90 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "ivas_cnst.h" +#include "ambi_convert.h" + +int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) +{ + assert( order <= 3 ); + + if ( in_format == AMBI_FMT_ACN_SN3D ) + { + if ( out_format == AMBI_FMT_ACN_N3D ) + { + renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_N3D ); + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); + } + else if ( out_format == AMBI_FMT_FM_MAXN ) + { + renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_MAXN ); + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); + } + else if ( out_format == AMBI_FMT_SID_SN3D ) + { + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); + } + else if ( out_format == AMBI_FMT_SID_N3D ) + { + renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_N3D ); + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); + } + else + { + assert( 0 && "Unsupported conversion" ); + } + } + else if ( in_format == AMBI_FMT_ACN_N3D ) + { + } + else + { + assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + } + + return 0; +} + +int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ) +{ + int16_t nchan = ( order + 1 ) * ( order + 1 ); + + return 0; +} + +int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) +{ + int16_t nchan = ( order + 1 ) * ( order + 1 ); + + return 0; +} diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h new file mode 100644 index 0000000000..c4ad6d234f --- /dev/null +++ b/lib_util/ambi_convert.h @@ -0,0 +1,66 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include + +typedef enum +{ + AMBI_FMT_ACN_SN3D = 0, + AMBI_FMT_ACN_N3D, + + AMBI_FMT_FM_MAXN, + + AMBI_FMT_SID_SN3D, + AMBI_FMT_SID_N3D +} AMBI_FMT; + +typedef enum +{ + AMBI_NORM_SN3D = 0, + AMBI_NORM_N3D = 1, + AMBI_NORM_MAXN = 2 +} AMBI_CHANNEL_NORM; + +typedef enum +{ + AMBI_CHANNEL_ORDER_ACN = 0, + AMBI_CHANNEL_ORDER_FM = 1, + AMBI_CHANNEL_ORDER_SID = 2 +} AMBI_CHANNEL_ORDER; + +int16_t convert_ambi_format(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format); + +int16_t renormalize_channels(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format); + +int16_t reorder_channels(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format); + + -- GitLab From 635182b05d02adeb207f172cd4f08433aae7d678 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 10:40:18 +0100 Subject: [PATCH 002/102] re-order conversion options in convert_ambi_format --- lib_util/ambi_cenvert.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index 711baba8d5..327a4918bf 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -43,7 +43,6 @@ int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], in if ( out_format == AMBI_FMT_ACN_N3D ) { renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_N3D ); - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); } else if ( out_format == AMBI_FMT_FM_MAXN ) { @@ -64,8 +63,30 @@ int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], in assert( 0 && "Unsupported conversion" ); } } - else if ( in_format == AMBI_FMT_ACN_N3D ) + else if ( out_format == AMBI_FMT_ACN_SN3D ) { + if ( in_format == AMBI_FMT_ACN_N3D ) + { + renormalize_channels( in, out, order, AMBI_NORM_N3D, AMBI_NORM_SN3D ); + } + else if ( in_format == AMBI_FMT_FM_MAXN ) + { + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_FM, AMBI_CHANNEL_ORDER_ACN ); + renormalize_channels( in, out, order, AMBI_NORM_MAXN, AMBI_NORM_SN3D ); + } + else if ( in_format == AMBI_FMT_SID_SN3D ) + { + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); + } + else if ( in_format == AMBI_FMT_SID_N3D ) + { + reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); + renormalize_channels( in, out, order, AMBI_NORM_N3D, AMBI_NORM_SN3D ); + } + else + { + assert( 0 && "Unsupported conversion" ); + } } else { -- GitLab From f612094a16e15a7ea9ebff4097f2984666f46343 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 10:59:07 +0100 Subject: [PATCH 003/102] insert arrays with conversion factors for N3D<->SN3D --- lib_util/ambi_cenvert.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index 327a4918bf..9d41035f0e 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -34,6 +34,30 @@ #include "ivas_cnst.h" #include "ambi_convert.h" +#define SQRT_3 1.7320508f +#define SQRT_5 2.2360679f +#define SQRT_7 2.64575131f + +#define INV_SQRT_3 0.5773502f +#define INV_SQRT_5 0.4472135f +#define INV_SQRT_7 0.3779644f + +#define AMBI_MAX_CHANNELS 16 + +static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, + SQRT_3, SQRT_3, SQRT_3, + SQRT_5, SQRT_5, SQRT_5, SQRT_5, SQRT_5, + SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7 +}; + +static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, + INV_SQRT_3, INV_SQRT_3, INV_SQRT_3, + INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, + INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7 +}; + + + int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); @@ -100,6 +124,9 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i { int16_t nchan = ( order + 1 ) * ( order + 1 ); + /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ + + return 0; } -- GitLab From 7cf0c276b11338e233b2180d9f76a66a7833cd61 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 11:36:15 +0100 Subject: [PATCH 004/102] add more conversion tables --- lib_util/ambi_cenvert.c | 67 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index 9d41035f0e..7fbd457809 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -42,6 +42,16 @@ #define INV_SQRT_5 0.4472135f #define INV_SQRT_7 0.3779644f +#define TWO_OVER_SQRT_3 1.1547005f +#define SQRT_8_OVER_5 1.2649110f +#define SQRT_3_OVER_5 0.7745966f +#define SQRT_45_OVER_32 1.1858541f + +#define INV_TWO_OVER_SQRT_3 0.8660254f +#define INV_SQRT_8_OVER_5 0.7905694f +#define INV_SQRT_3_OVER_5 1.2909944f +#define INV_SQRT_45_OVER_32 0.8432740f + #define AMBI_MAX_CHANNELS 16 static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, @@ -56,7 +66,16 @@ static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7 }; +static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, + 1.0f, 1.0f, 1.0f, + TWO_OVER_SQRT_3, TWO_OVER_SQRT_3, 1, TWO_OVER_SQRT_3, TWO_OVER_SQRT_3, + SQRT_8_OVER_5, SQRT_3_OVER_5, SQRT_45_OVER_32, 1, SQRT_45_OVER_32, SQRT_3_OVER_5, SQRT_8_OVER_5 +}; +static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, + 1.0f, 1.0f, 1.0f, + INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, 1.0f, INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, + INV_SQRT_8_OVER_5, INV_SQRT_3_OVER_5, INV_SQRT_45_OVER_32, 1.0f, INV_SQRT_45_OVER_32, INV_SQRT_3_OVER_5, INV_SQRT_8_OVER_5 }; int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { @@ -122,10 +141,54 @@ int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], in int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ) { - int16_t nchan = ( order + 1 ) * ( order + 1 ); + int16_t n_chan = ( order + 1 ) * ( order + 1 ); + int16_t i_chan, i; + float *conversion_table; - /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ + if ( in_format == AMBI_NORM_SN3D ) + { + if ( out_format == AMBI_NORM_N3D ) + { + conversion_table = SN3D_N3D; + } + if ( out_format == AMBI_NORM_MAXN ) + { + conversion_table = SN3D_MAXN; + } + else + { + assert( 0 && "Unsupported conversion" ); + } + } + else if ( out_format == AMBI_NORM_SN3D ) + { + if ( in_format == AMBI_NORM_N3D ) + { + conversion_table = N3D_SN3D; + } + if ( in_format == AMBI_NORM_MAXN ) + { + conversion_table = MAXN_SN3D; + } + else + { + assert( 0 && "Unsupported conversion" ); + } + } + else + { + assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + } + /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ + for (i_chan = 0; i_chan < n_chan; i_chan++) + { + float conversion_factor = conversion_table[i_chan]; + for (i = 0; i < L_FRAME48k; i++) + { + out[i_chan][i] = in[i_chan][i] * conversion_factor; + } + } return 0; } -- GitLab From b0d818ec57a1977463e66734c3c9f02ae8b6c558 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 11:59:09 +0100 Subject: [PATCH 005/102] add channel re-ordering tables --- lib_util/ambi_cenvert.c | 79 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index 7fbd457809..8cd0e46235 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -54,6 +54,10 @@ #define AMBI_MAX_CHANNELS 16 +/* -------------------------------- + normalization conversion tables + -------------------------------- */ + static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, SQRT_3, SQRT_3, SQRT_3, SQRT_5, SQRT_5, SQRT_5, SQRT_5, SQRT_5, @@ -77,6 +81,40 @@ static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, 1.0f, INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, INV_SQRT_8_OVER_5, INV_SQRT_3_OVER_5, INV_SQRT_45_OVER_32, 1.0f, INV_SQRT_45_OVER_32, INV_SQRT_3_OVER_5, INV_SQRT_8_OVER_5 }; +/* ---------------------------- + channel re-ordering tables + ---------------------------- */ + +static const int16_t REORDER_FM_ACN[AMBI_MAX_CHANNELS] = { 0, + 2, 3, 1, + 8, 6, 4, 5, 7, + 15, 13, 11, 9, 10, 12, 14 +}; + +static const int16_t REORDER_SID_ACN[AMBI_MAX_CHANNELS] = { 0, + 2, 3, 1, + 5, 7, 8, 6, 4, + 10, 12, 14, 15, 13, 11, 9 +}; + +static const int16_t REORDER_ACN_FM[AMBI_MAX_CHANNELS] = { 0, + 3, 1, 2, + 6, 7, 5, 8, 4, + 12, 13, 11, 14, 10, 15, 9 +}; + +static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, + 3, 1, 2, + 8, 4, 7, 5, 6, + 15, 9, 14, 10, 13, 11, 12 +}; + + +/* ---------------------------------- + API functions for the conversion + ---------------------------------- */ + + int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); @@ -143,7 +181,9 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; - float *conversion_table; + const float *conversion_table; + + /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ if ( in_format == AMBI_NORM_SN3D ) { @@ -180,7 +220,6 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ for (i_chan = 0; i_chan < n_chan; i_chan++) { float conversion_factor = conversion_table[i_chan]; @@ -196,6 +235,42 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) { int16_t nchan = ( order + 1 ) * ( order + 1 ); + int16_t *idx_table; + + if ( in_format == AMBI_CHANNEL_ORDER_ACN ) + { + if ( out_format == AMBI_CHANNEL_ORDER_FM ) + { + idx_table = REORDER_ACN_FM; + } + if ( out_format == AMBI_CHANNEL_ORDER_SID ) + { + idx_table = REORDER_ACN_SID; + } + else + { + assert( 0 && "Unsupported conversion" ); + } + } + else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) + { + if ( in_format == AMBI_CHANNEL_ORDER_FM ) + { + idx_table = REORDER_ACN_FM; + } + if ( in_format == AMBI_CHANNEL_ORDER_SID ) + { + idx_table = REORDER_ACN_SID; + } + else + { + assert( 0 && "Unsupported conversion" ); + } + } + else + { + assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + } return 0; } -- GitLab From d77535cbd50aa372740fe32285d0ec92b89b7d04 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 12:52:49 +0100 Subject: [PATCH 006/102] add code to re-order the channels --- lib_util/ambi_cenvert.c | 22 +++++++++++++++++++--- scripts/check-format.sh | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index 8cd0e46235..e79998215e 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -31,6 +31,7 @@ *******************************************************************************************************/ #include +#include #include "ivas_cnst.h" #include "ambi_convert.h" @@ -181,7 +182,7 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; - const float *conversion_table; + const float *conversion_table = 0; /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ @@ -234,8 +235,10 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) { - int16_t nchan = ( order + 1 ) * ( order + 1 ); - int16_t *idx_table; + int16_t n_chan = ( order + 1 ) * ( order + 1 ); + int16_t i_chan, i; + float tmp[AMBI_MAX_CHANNELS]; + const int16_t *idx_table = 0; if ( in_format == AMBI_CHANNEL_ORDER_ACN ) { @@ -272,5 +275,18 @@ int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16 assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } + for ( i = 0; i < L_FRAME48k; i++ ) + { + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + int16_t idx = idx_table[i_chan]; + tmp[i_chan] = in[idx][i]; + } + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + out[i_chan][i] = tmp[i_chan]; + } + } + return 0; } diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 079a1ed334..154349de9f 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -38,7 +38,7 @@ if [ ! -d "lib_com" ]; then exit 255 fi -CLANG_FORMAT=clang-format +CLANG_FORMAT=./clang-format.exe CLANG_FORMAT_REQUIRED_VERSION="13.0" # list (with space between entries) of substrings that are excluded from the file list, e.g. very large files -- GitLab From 90df46559400dea51db1c1d68170ad8301f7c4f9 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 13:17:10 +0100 Subject: [PATCH 007/102] add normalization tables for FM (with a factor of sqrt(2) as compared to MAXN) --- lib_util/ambi_cenvert.c | 68 +++++++++++++++++++++++------------------ lib_util/ambi_convert.h | 9 +++--- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_cenvert.c index e79998215e..fb2875e918 100644 --- a/lib_util/ambi_cenvert.c +++ b/lib_util/ambi_cenvert.c @@ -35,23 +35,25 @@ #include "ivas_cnst.h" #include "ambi_convert.h" -#define SQRT_3 1.7320508f -#define SQRT_5 2.2360679f -#define SQRT_7 2.64575131f - -#define INV_SQRT_3 0.5773502f -#define INV_SQRT_5 0.4472135f -#define INV_SQRT_7 0.3779644f - -#define TWO_OVER_SQRT_3 1.1547005f -#define SQRT_8_OVER_5 1.2649110f -#define SQRT_3_OVER_5 0.7745966f -#define SQRT_45_OVER_32 1.1858541f - -#define INV_TWO_OVER_SQRT_3 0.8660254f -#define INV_SQRT_8_OVER_5 0.7905694f -#define INV_SQRT_3_OVER_5 1.2909944f -#define INV_SQRT_45_OVER_32 0.8432740f +#define SQRT_2_ 1.4142135f +#define SQRT_3_ 1.7320508f +#define SQRT_5_ 2.2360679f +#define SQRT_7_ 2.64575131f + +#define INV_SQRT_2_ 0.7071067f +#define INV_SQRT_3_ 0.5773502f +#define INV_SQRT_5_ 0.4472135f +#define INV_SQRT_7_ 0.3779644f + +#define TWO_OVER_SQRT_3_ 1.1547005f +#define SQRT_8_OVER_5_ 1.2649110f +#define SQRT_3_OVER_5_ 0.7745966f +#define SQRT_45_OVER_32_ 1.1858541f + +#define INV_TWO_OVER_SQRT_3_ 0.8660254f +#define INV_SQRT_8_OVER_5_ 0.7905694f +#define INV_SQRT_3_OVER_5_ 1.2909944f +#define INV_SQRT_45_OVER_32_ 0.8432740f #define AMBI_MAX_CHANNELS 16 @@ -60,27 +62,37 @@ -------------------------------- */ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, - SQRT_3, SQRT_3, SQRT_3, - SQRT_5, SQRT_5, SQRT_5, SQRT_5, SQRT_5, - SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7, SQRT_7 + SQRT_3_, SQRT_3_, SQRT_3_, + SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, + SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_ }; static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, - INV_SQRT_3, INV_SQRT_3, INV_SQRT_3, - INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, INV_SQRT_5, - INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7, INV_SQRT_7 + INV_SQRT_3_, INV_SQRT_3_, INV_SQRT_3_, + INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, + INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, - TWO_OVER_SQRT_3, TWO_OVER_SQRT_3, 1, TWO_OVER_SQRT_3, TWO_OVER_SQRT_3, - SQRT_8_OVER_5, SQRT_3_OVER_5, SQRT_45_OVER_32, 1, SQRT_45_OVER_32, SQRT_3_OVER_5, SQRT_8_OVER_5 + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, - INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, 1.0f, INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, - INV_SQRT_8_OVER_5, INV_SQRT_3_OVER_5, INV_SQRT_45_OVER_32, 1.0f, INV_SQRT_45_OVER_32, INV_SQRT_3_OVER_5, INV_SQRT_8_OVER_5 }; + INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, + INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; + +static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, + 1.0f, 1.0f, 1.0f, + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; + +static const float FM_MAXN[AMBI_MAX_CHANNELS] = { INV_SQRT_2, + 1.0f, 1.0f, 1.0f, + INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, + INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; /* ---------------------------- channel re-ordering tables @@ -110,12 +122,10 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, 15, 9, 14, 10, 13, 11, 12 }; - /* ---------------------------------- API functions for the conversion ---------------------------------- */ - int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index c4ad6d234f..d2296625c3 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -46,15 +46,16 @@ typedef enum typedef enum { AMBI_NORM_SN3D = 0, - AMBI_NORM_N3D = 1, - AMBI_NORM_MAXN = 2 + AMBI_NORM_N3D, + AMBI_NORM_MAXN, + AMBI_NORM_FM } AMBI_CHANNEL_NORM; typedef enum { AMBI_CHANNEL_ORDER_ACN = 0, - AMBI_CHANNEL_ORDER_FM = 1, - AMBI_CHANNEL_ORDER_SID = 2 + AMBI_CHANNEL_ORDER_FM, + AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; int16_t convert_ambi_format(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format); -- GitLab From e0928ecaf1f5a20ef8591c91e8811b62f8205c3c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 13:18:15 +0100 Subject: [PATCH 008/102] fix typo in file name --- Workspace_msvc/lib_util.vcxproj | 2 +- lib_util/{ambi_cenvert.c => ambi_convert.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib_util/{ambi_cenvert.c => ambi_convert.c} (100%) diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index bd70056f36..72f1c9f7c4 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -100,7 +100,7 @@ - + diff --git a/lib_util/ambi_cenvert.c b/lib_util/ambi_convert.c similarity index 100% rename from lib_util/ambi_cenvert.c rename to lib_util/ambi_convert.c -- GitLab From b64f5f62c6ed2058a972324c3a81703b0e6396a1 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 13:33:00 +0100 Subject: [PATCH 009/102] fix formattting --- lib_util/ambi_convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index fb2875e918..5044325114 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -231,10 +231,10 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - for (i_chan = 0; i_chan < n_chan; i_chan++) + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { float conversion_factor = conversion_table[i_chan]; - for (i = 0; i < L_FRAME48k; i++) + for ( i = 0; i < L_FRAME48k; i++ ) { out[i_chan][i] = in[i_chan][i] * conversion_factor; } -- GitLab From b0712abeb92fd51dc4330ddb6db3170307a4f7b6 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 15:14:23 +0100 Subject: [PATCH 010/102] implement encoder command line option to select SBA input convention --- Workspace_msvc/lib_enc.vcxproj | 2 +- apps/encoder.c | 44 ++- lib_com/options.h | 2 + lib_enc/ivas_enc.c | 589 +++++++++++++++++---------------- lib_enc/ivas_stat_enc.h | 3 + lib_enc/lib_enc.c | 19 +- lib_enc/lib_enc.h | 8 + lib_util/ambi_convert.h | 11 +- 8 files changed, 377 insertions(+), 301 deletions(-) diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index aac96693ce..f1ff59c863 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_util;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks diff --git a/apps/encoder.c b/apps/encoder.c index b00f4f75fd..6578c82ee2 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -38,6 +38,9 @@ #include "ism_file_reader.h" #include "jbm_file_reader.h" #include "masa_file_reader.h" +#ifdef AMBISONICS_CONVENTIONS +#include "ambi_convert.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -58,8 +61,7 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig -{ +typedef union _EncInputFormatConfig { /* MONO details */ bool stereoToMonoDownmix; @@ -121,6 +123,9 @@ typedef struct bool max_bwidth_user; IVAS_ENC_BANDWIDTH maxBandwidth; const char *bandwithProfileFile; +#ifdef AMBISONICS_CONVENTIONS + int16_t sba_input_fmt; +#endif IVAS_ENC_DTX_CONFIG dtxConfig; int32_t initBitrate; const char *bitrateProfileFile; @@ -408,6 +413,10 @@ int main( #ifdef DEBUG_SBA_AUDIO_DUMP , &numTransportChannels +#endif +#ifdef AMBISONICS_CONVENTIONS + , + arg.sba_input_fmt #endif ) ) != IVAS_ERR_OK ) { @@ -431,7 +440,12 @@ int main( } break; case IVAS_ENC_INPUT_SBA_ISM: - if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca +#ifdef AMBISONICS_CONVENTIONS + , + arg.sba_input_fmt +#endif + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); exit( -1 ); @@ -1183,6 +1197,30 @@ static bool parseCmdlIVAS_enc( } } + /* ---------------------------------------------------------------- + * SBA input convention + *------------------------------------------------------------------*/ +#ifdef AMBISONICS_CONVENTIONS + else if ( strcmp( argv_to_upper, "SBA_CONVENTION" ) == 0 ) + { + i++; + arg->inputFormat = AMBI_FMT_ACN_SN3D; + + /* SBA configuration */ + if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + else + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number!\n\n" ); + usage_enc(); + return false; + } + } +#endif + /*-----------------------------------------------------------------* * MIME output file format *-----------------------------------------------------------------*/ diff --git a/lib_com/options.h b/lib_com/options.h index 52357d6c25..38e2f8d580 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,6 +158,8 @@ #define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ +#define AMBISONICS_CONVENTIONS + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5ddcf9a506..73533d0b3a 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -34,6 +34,7 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" +#include "ambi_convert.h" #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" @@ -79,7 +80,7 @@ ivas_error ivas_enc( nchan_inp = hEncoderConfig->nchan_inp; ivas_total_brate = hEncoderConfig->ivas_total_brate; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -126,439 +127,449 @@ ivas_error ivas_enc( dbgwrite( data_f[LFE_CHANNEL], sizeof( float ), n_samples_chan, 1, "./res/lfe_input" ); #endif - if ( ivas_format == SBA_FORMAT ) +#ifdef AMBISONICS_CONVENTIONS + if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) { - if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + if ( hEncoderConfig->sba_input_fmt != 0 ) { - return error; + convert_ambi_format( data_f, data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_input_fmt, AMBI_FMT_ACN_SN3D ); } - } - else if ( ivas_format == SBA_ISM_FORMAT ) - { - if ( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + } +#endif + + if ( ivas_format == SBA_FORMAT ) + { + if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_ISM_FORMAT ) { - return error; + if ( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * HP filtering *----------------------------------------------------------------*/ - n = getNumChanAnalysis( st_ivas ); + n = getNumChanAnalysis( st_ivas ); #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC - /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ - for ( i = 0; i < n; i++ ) - { - if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) ) + /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ + for ( i = 0; i < n; i++ ) { - hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); - } - else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) - { - hp20( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) ) + { + hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + } + else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) + { + hp20( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + } } - } #endif - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ - ivas_write_format( st_ivas ); + ivas_write_format( st_ivas ); - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ - if ( ivas_format == STEREO_FORMAT ) - { - st_ivas->hCPE[0]->element_brate = ivas_total_brate; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + if ( ivas_format == STEREO_FORMAT ) { - return error; - } - } - else if ( ivas_format == ISM_FORMAT ) - { - /* select ISM format mode; reconfigure the ISM format encoder */ - if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) - { - ivas_param_ism_enc( st_ivas, data_f, input_frame ); - - /* Stereo DMX generation */ - ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); - - /* Core coding of Stereo DMX */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MODE_DISC ) + else if ( ivas_format == ISM_FORMAT ) { - /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + /* select ISM format mode; reconfigure the ISM format encoder */ + if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) - { - /* MASA configuration */ - if ( ivas_format == MASA_FORMAT ) - { - ivas_masa_enc_reconfigure( st_ivas ); - } - /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + ivas_param_ism_enc( st_ivas, data_f, input_frame ); - if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) - { - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ + /* Stereo DMX generation */ + ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; + /* Core coding of Stereo DMX */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + else if ( st_ivas->ism_mode == ISM_MODE_DISC ) { - return error; + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } } - else if ( ivas_format == SBA_FORMAT ) + else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) { - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + /* MASA configuration */ + if ( ivas_format == MASA_FORMAT ) { - return error; + ivas_masa_enc_reconfigure( st_ivas ); } - } - if ( ivas_format == SBA_FORMAT ) - { - ivas_sba_getTCs( data_f, st_ivas, input_frame ); - } + /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) { - return error; + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ + + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ - { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + else if ( ivas_format == SBA_FORMAT ) { - return error; + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ - { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + + if ( ivas_format == SBA_FORMAT ) { - return error; + ivas_sba_getTCs( data_f, st_ivas, input_frame ); } - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - float *data_separated_object; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; - - flag_omasa_ener_brate = 0; - - /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ - if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) - { - v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); - mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); - } - - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); - idx_separated_object = 0; - - data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; - - /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); - } - - /* Encode ISMs transport channels */ - n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) { - return error; + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - return error; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + else if ( ivas_format == MASA_ISM_FORMAT ) { - flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); + float *data_separated_object; + int16_t idx_separated_object; + int16_t flag_omasa_ener_brate; - /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + flag_omasa_ener_brate = 0; + + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { - return error; + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - n = st_ivas->hEncoderConfig->nchan_ism; - } - - hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( st_ivas->nSCE > 0 ) - { - /* update pointer to the buffer of indices (ISM indices were alredy written) */ - hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; - } + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - /* Encode MASA parameters and write MASA metadata bitstream */ - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Configuration of combined-format bit-budget distribution */ -#ifdef DEBUG_MODE_INFO - ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); -#else - ivas_set_surplus_brate_enc( st_ivas ); -#endif + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + idx_separated_object = 0; - /* Encode MASA transport channels */ - if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( ivas_format == SBA_ISM_FORMAT ) - { - int16_t planar_sba_orig; - planar_sba_orig = hEncoderConfig->sba_planar; + data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; - /* Analyze objects and determine needed audio signals */ - ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + } - if ( st_ivas->ism_mode == ISM_MODE_NONE ) - { - /*once SBA and ISM are combined into SBA signal then disable planar flag*/ - hEncoderConfig->sba_planar = 0; - if ( st_ivas->nchan_transport == 1 ) + /* Encode ISMs transport channels */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + { + return error; + } } - else + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + { + return error; + } } - - /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - return error; + flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); + + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + n = st_ivas->hEncoderConfig->nchan_ism; } - hEncoderConfig->sba_planar = planar_sba_orig; - } - else - { - n = hEncoderConfig->nchan_ism; hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + if ( st_ivas->nSCE > 0 ) { - return error; + /* update pointer to the buffer of indices (ISM indices were alredy written) */ + hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; } - /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + /* Encode MASA parameters and write MASA metadata bitstream */ + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } - /* get SBA TCs */ - ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); - } + /* Configuration of combined-format bit-budget distribution */ +#ifdef DEBUG_MODE_INFO + ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); +#else + ivas_set_surplus_brate_enc( st_ivas ); +#endif - /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ - { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + /* Encode MASA transport channels */ + if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + else if ( ivas_format == SBA_ISM_FORMAT ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + int16_t planar_sba_orig; + planar_sba_orig = hEncoderConfig->sba_planar; + + /* Analyze objects and determine needed audio signals */ + ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); + + if ( st_ivas->ism_mode == ISM_MODE_NONE ) { - return error; - } - } - } - else if ( ivas_format == MC_FORMAT ) - { - /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + /*once SBA and ISM are combined into SBA signal then disable planar flag*/ + hEncoderConfig->sba_planar = 0; + if ( st_ivas->nchan_transport == 1 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } + else + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } - /* LFE low pass filter */ - ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); + hEncoderConfig->sba_planar = planar_sba_orig; + } + else + { + n = hEncoderConfig->nchan_ism; + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - /* LFE channel encoder */ - if ( st_ivas->mc_mode == MC_MODE_MCT ) - { - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); - } + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( st_ivas->mc_mode == MC_MODE_MCT ) - { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; + /* get SBA TCs */ + ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); } - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) - { - /* encode MC ParamUpmix parameters and write bitstream */ - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) { - return error; + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) - { - /* encode Parametric MC parameters and write bitstream */ - ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); - - if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + else if ( ivas_format == MC_FORMAT ) { - if ( st_ivas->hMcMasa->separateChannelEnabled ) + /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ + if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { - hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ + return error; } - ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + /* LFE low pass filter */ + ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + /* LFE channel encoder */ + if ( st_ivas->mc_mode == MC_MODE_MCT ) { - return error; + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); } - if ( st_ivas->hMcMasa->separateChannelEnabled ) + if ( st_ivas->mc_mode == MC_MODE_MCT ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) { - if ( st_ivas->nSCE == 1 ) + /* encode Parametric MC parameters and write bitstream */ + ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); + + if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + else if ( st_ivas->nCPE > 1 ) { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + { + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ + } + + ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); + + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hMcMasa->separateChannelEnabled ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } + else + { + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } } } - } - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * Common updates *----------------------------------------------------------------*/ - hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; #ifdef DEBUG_MODE_INFO - { - float tmpF = ivas_total_brate / 1000.0f; - dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); - } + { + float tmpF = ivas_total_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); + } #endif - pop_wmops(); - return error; -} + pop_wmops(); + return error; + } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3962ac055f..f92a598afb 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1188,6 +1188,9 @@ typedef struct encoder_config_structure int16_t Opt_DTX_ON; /* flag indicating DTX operation */ int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ +#ifdef AMBISONICS_CONVENTIONS + int16_t sba_input_fmt; +#endif int16_t Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ int16_t rf_fec_offset; /* RF FEC offset */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 4a4be81734..39026d6992 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -492,6 +492,10 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( , int16_t *numTransportChannels #endif +#ifdef AMBISONICS_CONVENTIONS + , + const int16_t sba_input_fmt +#endif ) { ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -509,6 +513,10 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; +#ifdef AMBISONICS_CONVENTIONS + hEncoderConfig->sba_input_fmt = sba_input_fmt; +#endif + /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ @@ -548,6 +556,10 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ const bool Opt_PCA_ON /* i : PCA option flag */ +#ifdef AMBISONICS_CONVENTIONS + , + const int16_t sba_input_fmt +#endif ) { Encoder_Struct *st_ivas; @@ -562,11 +574,14 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( { return IVAS_ERR_TOO_MANY_INPUTS; } - st_ivas = hIvasEnc->st_ivas; + st_ivas = hIvasEnc->st_ivas; st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ st_ivas->hEncoderConfig->sba_planar = isPlanar; st_ivas->hEncoderConfig->sba_order = order; +#ifdef AMBISONICS_CONVENTIONS + st_ivas->hEncoderConfig->sba_input_fmt = sba_input_fmt; +#endif /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ @@ -1079,7 +1094,7 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { - return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); + return ( int16_t )( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } /*---------------------------------------------------------------------* diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 2f40c1ab1b..58860e3107 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -223,6 +223,10 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ const bool Opt_PCA_ON /* i : PCA option flag */ +#ifdef AMBISONICS_CONVENTIONS + , + const int16_t sba_input_fmt +#endif ); /*! r: error code */ @@ -243,6 +247,10 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( , int16_t *numTransportChannels #endif +#ifdef AMBISONICS_CONVENTIONS + , + const int16_t sba_input_fmt +#endif ); /*! r: error code */ diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index d2296625c3..598c830ab8 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -31,16 +31,15 @@ *******************************************************************************************************/ #include +#include "ivas_cnst.h" typedef enum { AMBI_FMT_ACN_SN3D = 0, - AMBI_FMT_ACN_N3D, - - AMBI_FMT_FM_MAXN, - - AMBI_FMT_SID_SN3D, - AMBI_FMT_SID_N3D + AMBI_FMT_ACN_N3D = 1, + AMBI_FMT_FM_MAXN = 2 , + AMBI_FMT_SID_SN3D = 3, + AMBI_FMT_SID_N3D = 4 } AMBI_FMT; typedef enum -- GitLab From 1fc47fa610b421e5cda8691af1a30a2f191ee4f2 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 15:26:31 +0100 Subject: [PATCH 011/102] fix formatting --- apps/encoder.c | 19 +- lib_enc/ivas_enc.c | 582 ++++++++++++++++++++-------------------- lib_enc/lib_enc.c | 2 +- lib_util/ambi_convert.c | 91 +++---- lib_util/ambi_convert.h | 14 +- 5 files changed, 350 insertions(+), 358 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 6578c82ee2..1e88ada4af 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -61,7 +61,8 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig { +typedef union _EncInputFormatConfig +{ /* MONO details */ bool stereoToMonoDownmix; @@ -415,8 +416,8 @@ int main( &numTransportChannels #endif #ifdef AMBISONICS_CONVENTIONS - , - arg.sba_input_fmt + , + arg.sba_input_fmt #endif ) ) != IVAS_ERR_OK ) { @@ -440,12 +441,12 @@ int main( } break; case IVAS_ENC_INPUT_SBA_ISM: - if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca + if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca #ifdef AMBISONICS_CONVENTIONS - , - arg.sba_input_fmt + , + arg.sba_input_fmt #endif - ) ) != IVAS_ERR_OK ) + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); exit( -1 ); @@ -1198,8 +1199,8 @@ static bool parseCmdlIVAS_enc( } /* ---------------------------------------------------------------- - * SBA input convention - *------------------------------------------------------------------*/ + * SBA input convention + *------------------------------------------------------------------*/ #ifdef AMBISONICS_CONVENTIONS else if ( strcmp( argv_to_upper, "SBA_CONVENTION" ) == 0 ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 73533d0b3a..5869e28a51 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -80,7 +80,7 @@ ivas_error ivas_enc( nchan_inp = hEncoderConfig->nchan_inp; ivas_total_brate = hEncoderConfig->ivas_total_brate; - input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -134,442 +134,442 @@ ivas_error ivas_enc( { convert_ambi_format( data_f, data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_input_fmt, AMBI_FMT_ACN_SN3D ); } - } + } #endif - if ( ivas_format == SBA_FORMAT ) + if ( ivas_format == SBA_FORMAT ) + { + if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - else if ( ivas_format == SBA_ISM_FORMAT ) + } + else if ( ivas_format == SBA_ISM_FORMAT ) + { + if ( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * HP filtering *----------------------------------------------------------------*/ - n = getNumChanAnalysis( st_ivas ); + n = getNumChanAnalysis( st_ivas ); #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC - /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ - for ( i = 0; i < n; i++ ) + /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */ + for ( i = 0; i < n; i++ ) + { + if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) ) { - if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) ) - { - hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); - } - else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) - { - hp20( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); - } + hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); + } + else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) ) + { + hp20( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); } + } #endif - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ - ivas_write_format( st_ivas ); + ivas_write_format( st_ivas ); - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ - if ( ivas_format == STEREO_FORMAT ) + if ( ivas_format == STEREO_FORMAT ) + { + st_ivas->hCPE[0]->element_brate = ivas_total_brate; + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == ISM_FORMAT ) + { + /* select ISM format mode; reconfigure the ISM format encoder */ + if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { - st_ivas->hCPE[0]->element_brate = ivas_total_brate; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) + ivas_param_ism_enc( st_ivas, data_f, input_frame ); + + /* Stereo DMX generation */ + ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); + + /* Core coding of Stereo DMX */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == ISM_FORMAT ) + else if ( st_ivas->ism_mode == ISM_MODE_DISC ) { - /* select ISM format mode; reconfigure the ISM format encoder */ - if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } + } + } + else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + { + /* MASA configuration */ + if ( ivas_format == MASA_FORMAT ) + { + ivas_masa_enc_reconfigure( st_ivas ); + } - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) - { - ivas_param_ism_enc( st_ivas, data_f, input_frame ); + /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - /* Stereo DMX generation */ - ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); + if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + { + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ - /* Core coding of Stereo DMX */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; } - else if ( st_ivas->ism_mode == ISM_MODE_DISC ) + + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { - /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + else if ( ivas_format == SBA_FORMAT ) { - /* MASA configuration */ - if ( ivas_format == MASA_FORMAT ) + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { - ivas_masa_enc_reconfigure( st_ivas ); + return error; } + } - /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + if ( ivas_format == SBA_FORMAT ) + { + ivas_sba_getTCs( data_f, st_ivas, input_frame ); + } - if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ - - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - else if ( ivas_format == SBA_FORMAT ) + } + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - - if ( ivas_format == SBA_FORMAT ) + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - ivas_sba_getTCs( data_f, st_ivas, input_frame ); + return error; } + } + } + else if ( ivas_format == MASA_ISM_FORMAT ) + { + float *data_separated_object; + int16_t idx_separated_object; + int16_t flag_omasa_ener_brate; - /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + flag_omasa_ener_brate = 0; + + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) + { + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); + } + + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + idx_separated_object = 0; + + data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + } + + /* Encode ISMs transport channels */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } } - else if ( ivas_format == MASA_ISM_FORMAT ) + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - float *data_separated_object; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; - - flag_omasa_ener_brate = 0; + flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); - /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ - if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { - v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); - mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); + return error; } + n = st_ivas->hEncoderConfig->nchan_ism; + } - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( st_ivas->nSCE > 0 ) + { + /* update pointer to the buffer of indices (ISM indices were alredy written) */ + hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; + } + + /* Encode MASA parameters and write MASA metadata bitstream */ + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + { + return error; + } - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); - idx_separated_object = 0; + /* Configuration of combined-format bit-budget distribution */ +#ifdef DEBUG_MODE_INFO + ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); +#else + ivas_set_surplus_brate_enc( st_ivas ); +#endif - data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + /* Encode MASA transport channels */ + if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( ivas_format == SBA_ISM_FORMAT ) + { + int16_t planar_sba_orig; + planar_sba_orig = hEncoderConfig->sba_planar; - /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); - } + /* Analyze objects and determine needed audio signals */ + ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); - /* Encode ISMs transport channels */ - n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + /*once SBA and ISM are combined into SBA signal then disable planar flag*/ + hEncoderConfig->sba_planar = 0; + if ( st_ivas->nchan_transport == 1 ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ - { - return error; - } + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + else { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) - { - return error; - } + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); - /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) - { - return error; - } - n = st_ivas->hEncoderConfig->nchan_ism; + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + { + return error; } + hEncoderConfig->sba_planar = planar_sba_orig; + } + else + { + n = hEncoderConfig->nchan_ism; hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( st_ivas->nSCE > 0 ) + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { - /* update pointer to the buffer of indices (ISM indices were alredy written) */ - hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; + return error; } - /* Encode MASA parameters and write MASA metadata bitstream */ - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + /* SBA metadata encoding and SBA metadata bitstream writing */ + if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } - /* Configuration of combined-format bit-budget distribution */ -#ifdef DEBUG_MODE_INFO - ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); -#else - ivas_set_surplus_brate_enc( st_ivas ); -#endif + /* get SBA TCs */ + ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + } - /* Encode MASA transport channels */ - if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + /* core-coding of transport channels */ + if ( st_ivas->nSCE == 1 ) + { + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - int16_t planar_sba_orig; - planar_sba_orig = hEncoderConfig->sba_planar; - - /* Analyze objects and determine needed audio signals */ - ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar ); - - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - /*once SBA and ISM are combined into SBA signal then disable planar flag*/ - hEncoderConfig->sba_planar = 0; - if ( st_ivas->nchan_transport == 1 ) - { - hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; - } - else - { - hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - } - - /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) - { - return error; - } - - hEncoderConfig->sba_planar = planar_sba_orig; + return error; } - else + } + else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - n = hEncoderConfig->nchan_ism; - hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + return error; + } + } + } + else if ( ivas_format == MC_FORMAT ) + { + /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ + if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) - { - return error; - } + hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - /* SBA metadata encoding and SBA metadata bitstream writing */ - if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) - { - return error; - } + /* LFE low pass filter */ + ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); - /* get SBA TCs */ - ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); + /* LFE channel encoder */ + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + } + + if ( st_ivas->mc_mode == MC_MODE_MCT ) + { + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; } + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + /* encode MC ParamUpmix parameters and write bitstream */ + ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + { + /* encode Parametric MC parameters and write bitstream */ + ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); + + if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + else if ( st_ivas->nCPE > 1 ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == MC_FORMAT ) + else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { - /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + if ( st_ivas->hMcMasa->separateChannelEnabled ) { - return error; + hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ } - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - - /* LFE low pass filter */ - ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame ); + ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); - /* LFE channel encoder */ - if ( st_ivas->mc_mode == MC_MODE_MCT ) + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + return error; } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + if ( st_ivas->hMcMasa->separateChannelEnabled ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) - { - /* encode MC ParamUpmix parameters and write bitstream */ - ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); - st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + else { - /* encode Parametric MC parameters and write bitstream */ - ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); - - if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ - { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->nCPE > 1 ) + if ( st_ivas->nSCE == 1 ) { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) - { - if ( st_ivas->hMcMasa->separateChannelEnabled ) - { - hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ - } - - ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { - return error; - } - - if ( st_ivas->hMcMasa->separateChannelEnabled ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else - { - if ( st_ivas->nSCE == 1 ) - { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ - { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } } } + } - /*----------------------------------------------------------------* + /*----------------------------------------------------------------* * Common updates *----------------------------------------------------------------*/ - hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + hEncoderConfig->last_ivas_total_brate = ivas_total_brate; #ifdef DEBUG_MODE_INFO - { - float tmpF = ivas_total_brate / 1000.0f; - dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); - } + { + float tmpF = ivas_total_brate / 1000.0f; + dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" ); + } #endif - pop_wmops(); - return error; - } + pop_wmops(); + return error; +} diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 39026d6992..03d16c98e2 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1094,7 +1094,7 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { - return ( int16_t )( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); + return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } /*---------------------------------------------------------------------* diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 5044325114..317737482f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -40,10 +40,10 @@ #define SQRT_5_ 2.2360679f #define SQRT_7_ 2.64575131f -#define INV_SQRT_2_ 0.7071067f -#define INV_SQRT_3_ 0.5773502f -#define INV_SQRT_5_ 0.4472135f -#define INV_SQRT_7_ 0.3779644f +#define INV_SQRT_2_ 0.7071067f +#define INV_SQRT_3_ 0.5773502f +#define INV_SQRT_5_ 0.4472135f +#define INV_SQRT_7_ 0.3779644f #define TWO_OVER_SQRT_3_ 1.1547005f #define SQRT_8_OVER_5_ 1.2649110f @@ -57,27 +57,24 @@ #define AMBI_MAX_CHANNELS 16 -/* -------------------------------- +/* -------------------------------- normalization conversion tables -------------------------------- */ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, SQRT_3_, SQRT_3_, SQRT_3_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, - SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_ -}; + SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_ }; static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_3_, INV_SQRT_3_, INV_SQRT_3_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, - INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ -}; + INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, - SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ -}; + SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, @@ -101,26 +98,22 @@ static const float FM_MAXN[AMBI_MAX_CHANNELS] = { INV_SQRT_2, static const int16_t REORDER_FM_ACN[AMBI_MAX_CHANNELS] = { 0, 2, 3, 1, 8, 6, 4, 5, 7, - 15, 13, 11, 9, 10, 12, 14 -}; + 15, 13, 11, 9, 10, 12, 14 }; static const int16_t REORDER_SID_ACN[AMBI_MAX_CHANNELS] = { 0, - 2, 3, 1, - 5, 7, 8, 6, 4, - 10, 12, 14, 15, 13, 11, 9 -}; + 2, 3, 1, + 5, 7, 8, 6, 4, + 10, 12, 14, 15, 13, 11, 9 }; static const int16_t REORDER_ACN_FM[AMBI_MAX_CHANNELS] = { 0, 3, 1, 2, 6, 7, 5, 8, 4, - 12, 13, 11, 14, 10, 15, 9 -}; + 12, 13, 11, 14, 10, 15, 9 }; static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, 3, 1, 2, 8, 4, 7, 5, 6, - 15, 9, 14, 10, 13, 11, 12 -}; + 15, 9, 14, 10, 13, 11, 12 }; /* ---------------------------------- API functions for the conversion @@ -153,8 +146,8 @@ int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], in else { assert( 0 && "Unsupported conversion" ); - } - } + } + } else if ( out_format == AMBI_FMT_ACN_SN3D ) { if ( in_format == AMBI_FMT_ACN_N3D ) @@ -194,14 +187,14 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i int16_t i_chan, i; const float *conversion_table = 0; - /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ + /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ - if ( in_format == AMBI_NORM_SN3D ) + if ( in_format == AMBI_NORM_SN3D ) { - if ( out_format == AMBI_NORM_N3D ) - { - conversion_table = SN3D_N3D; - } + if ( out_format == AMBI_NORM_N3D ) + { + conversion_table = SN3D_N3D; + } if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; @@ -210,9 +203,9 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i { assert( 0 && "Unsupported conversion" ); } - } - else if ( out_format == AMBI_NORM_SN3D ) - { + } + else if ( out_format == AMBI_NORM_SN3D ) + { if ( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; @@ -225,20 +218,20 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i { assert( 0 && "Unsupported conversion" ); } - } + } else { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) - { - float conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) - { - out[i_chan][i] = in[i_chan][i] * conversion_factor; - } - } + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + float conversion_factor = conversion_table[i_chan]; + for ( i = 0; i < L_FRAME48k; i++ ) + { + out[i_chan][i] = in[i_chan][i] * conversion_factor; + } + } return 0; } @@ -250,7 +243,7 @@ int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16 float tmp[AMBI_MAX_CHANNELS]; const int16_t *idx_table = 0; - if ( in_format == AMBI_CHANNEL_ORDER_ACN ) + if ( in_format == AMBI_CHANNEL_ORDER_ACN ) { if ( out_format == AMBI_CHANNEL_ORDER_FM ) { @@ -285,18 +278,18 @@ int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16 assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - for ( i = 0; i < L_FRAME48k; i++ ) + for ( i = 0; i < L_FRAME48k; i++ ) { - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) - { - int16_t idx = idx_table[i_chan]; - tmp[i_chan] = in[idx][i]; - } + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + int16_t idx = idx_table[i_chan]; + tmp[i_chan] = in[idx][i]; + } for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { out[i_chan][i] = tmp[i_chan]; } - } + } return 0; } diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 598c830ab8..3251824ab8 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -37,7 +37,7 @@ typedef enum { AMBI_FMT_ACN_SN3D = 0, AMBI_FMT_ACN_N3D = 1, - AMBI_FMT_FM_MAXN = 2 , + AMBI_FMT_FM_MAXN = 2, AMBI_FMT_SID_SN3D = 3, AMBI_FMT_SID_N3D = 4 } AMBI_FMT; @@ -47,20 +47,18 @@ typedef enum AMBI_NORM_SN3D = 0, AMBI_NORM_N3D, AMBI_NORM_MAXN, - AMBI_NORM_FM + AMBI_NORM_FM } AMBI_CHANNEL_NORM; typedef enum { - AMBI_CHANNEL_ORDER_ACN = 0, + AMBI_CHANNEL_ORDER_ACN = 0, AMBI_CHANNEL_ORDER_FM, AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; -int16_t convert_ambi_format(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format); - -int16_t renormalize_channels(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format); - -int16_t reorder_channels(float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format); +int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); +int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); +int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); -- GitLab From 851575d92317c1b72d5fdd7874562fdc357790f8 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 15:43:14 +0100 Subject: [PATCH 012/102] change signatures of conversion functions to match the type of the float input buffer in the encoder --- apps/encoder.c | 2 +- lib_util/ambi_convert.c | 6 +++--- lib_util/ambi_convert.h | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 1e88ada4af..a2e2287694 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1205,7 +1205,7 @@ static bool parseCmdlIVAS_enc( else if ( strcmp( argv_to_upper, "SBA_CONVENTION" ) == 0 ) { i++; - arg->inputFormat = AMBI_FMT_ACN_SN3D; + arg->inputFormat = ( int16_t ) AMBI_FMT_ACN_SN3D; /* SBA configuration */ if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 317737482f..8155688354 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -119,7 +119,7 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, API functions for the conversion ---------------------------------- */ -int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) +int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); @@ -181,7 +181,7 @@ int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], in return 0; } -int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ) +int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; @@ -236,7 +236,7 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i return 0; } -int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) +int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 3251824ab8..9bc0bb5d86 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include -#include "ivas_cnst.h" typedef enum { @@ -57,8 +56,8 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; -int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); +int16_t convert_ambi_format( float* in[], float* out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); -int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); +int16_t renormalize_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); -int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); +int16_t reorder_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); -- GitLab From 843a8257b5162f4c6aafee6444577a4992282d30 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 15:54:09 +0100 Subject: [PATCH 013/102] fix encoder command line parsing --- apps/encoder.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index a2e2287694..68373f2c3e 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -125,7 +125,7 @@ typedef struct IVAS_ENC_BANDWIDTH maxBandwidth; const char *bandwithProfileFile; #ifdef AMBISONICS_CONVENTIONS - int16_t sba_input_fmt; + AMBI_FMT sba_input_fmt; #endif IVAS_ENC_DTX_CONFIG dtxConfig; int32_t initBitrate; @@ -1202,10 +1202,10 @@ static bool parseCmdlIVAS_enc( * SBA input convention *------------------------------------------------------------------*/ #ifdef AMBISONICS_CONVENTIONS - else if ( strcmp( argv_to_upper, "SBA_CONVENTION" ) == 0 ) + else if ( strcmp( argv_to_upper, "-SBA_CONVENTION" ) == 0 ) { i++; - arg->inputFormat = ( int16_t ) AMBI_FMT_ACN_SN3D; + arg->sba_input_fmt = AMBI_FMT_ACN_SN3D; /* SBA configuration */ if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) @@ -1219,6 +1219,7 @@ static bool parseCmdlIVAS_enc( usage_enc(); return false; } + arg->sba_input_fmt = tmp; } #endif -- GitLab From a26392d2d13e8c69e49b3ece68097046a1dff548 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 15:57:17 +0100 Subject: [PATCH 014/102] fix table selection --- lib_util/ambi_convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8155688354..8a6461d51f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -195,7 +195,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = SN3D_N3D; } - if ( out_format == AMBI_NORM_MAXN ) + else if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; } @@ -210,7 +210,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = N3D_SN3D; } - if ( in_format == AMBI_NORM_MAXN ) + else if ( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; } -- GitLab From b1436fe650cd93eb3cdc9b658ccb73fd4149020e Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 18 Mar 2024 17:15:39 +0100 Subject: [PATCH 015/102] implement sba output convention selection on the decoder command line --- Workspace_msvc/decoder.vcxproj | 2 +- Workspace_msvc/lib_dec.vcxproj | 2 +- Workspace_msvc/lib_rend.vcxproj | 2 +- apps/decoder.c | 38 ++++++++++++++++++++++++++++++--- lib_dec/ivas_stat_dec.h | 16 ++++++++------ lib_dec/lib_dec.c | 8 +++++++ lib_dec/lib_dec.h | 4 ++++ lib_enc/ivas_stat_enc.h | 4 ++-- lib_util/ambi_convert.h | 5 +++++ 9 files changed, 67 insertions(+), 14 deletions(-) diff --git a/Workspace_msvc/decoder.vcxproj b/Workspace_msvc/decoder.vcxproj index 2228349d5e..a2661ac082 100644 --- a/Workspace_msvc/decoder.vcxproj +++ b/Workspace_msvc/decoder.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_dec;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) + ..\lib_dec;..\lib_util;..\lib_com;..\lib_util;..\lib_debug;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) EnableFastChecks diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index ea7ad47897..cf9efaf458 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_util;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index de8e09d283..ce6ff51bf7 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_util;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks diff --git a/apps/decoder.c b/apps/decoder.c index d993eb4144..3114484255 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -43,6 +43,9 @@ #include "masa_file_writer.h" #include "render_config_reader.h" #include "rotation_file_reader.h" +#ifdef AMBISONICS_CONVENTIONS +#include "ambi_convert.h" +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT #include "split_render_file_read_write.h" #endif @@ -144,6 +147,9 @@ typedef struct uint16_t acousticEnvironmentId; int16_t Opt_dpid_on; uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS]; +#ifdef AMBISONICS_CONVENTIONS + AMBI_FMT sba_output_fmt; +#endif } DecArguments; @@ -433,7 +439,12 @@ int main( asked_frame_size = arg.renderFramesize; if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, - arg.Opt_dpid_on, arg.acousticEnvironmentId, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) + arg.Opt_dpid_on, arg.acousticEnvironmentId, arg.delayCompensationEnabled +#ifdef AMBISONICS_CONVENTIONS + , + arg.sba_output_fmt +#endif + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -1253,7 +1264,28 @@ static bool parseCmdlIVAS_dec( } #endif #endif /* #ifdef DEBUGGING */ +#ifdef AMBISONICS_CONVENTIONS + else if ( strcmp( argv_to_upper, "-SBA_CONVENTION" ) == 0 ) + { + int16_t tmp; + i++; + arg->sba_output_fmt = AMBI_FMT_ACN_SN3D; + /* SBA configuration */ + if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + else + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number!\n\n" ); + usage_dec(); + return false; + } + arg->sba_output_fmt = tmp; + } +#endif else if ( strcmp( argv_to_upper, "-MIME" ) == 0 ) { arg->inputFormat = IVAS_DEC_INPUT_FORMAT_MIME; @@ -1741,7 +1773,7 @@ static void usage_dec( void ) static int16_t app_own_random( int16_t *seed ) { - *seed = (int16_t) ( *seed * 31821L + 13849L ); + *seed = ( int16_t )( *seed * 31821L + 13849L ); return ( *seed ); } @@ -3212,7 +3244,7 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + if ( nextPacketRcvTime_ms == ( uint32_t )( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) { break; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4deb6748e2..a1ef49e599 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -38,6 +38,7 @@ #include "cnst.h" #include "ivas_cnst.h" #include "stat_dec.h" +#include "ambi_convert.h" #include "ivas_stat_com.h" #include "ivas_stat_rend.h" @@ -1016,12 +1017,15 @@ typedef struct decoder_config_structure int16_t Opt_Headrotation; /* indicates whether head-rotation is used */ int16_t Opt_RendConfigCustom; /* indicates whether Renderer configuration custom setup is used */ IVAS_HEAD_ORIENT_TRK_T orientation_tracking; /* indicates orientation tracking type */ - int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ - float non_diegetic_pan_gain; /* non diegetic panning gain*/ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ - int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ - int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ +#ifdef AMBISONICS_CONVENTIONS + AMBI_FMT sba_output_fmt; +#endif + int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ + float non_diegetic_pan_gain; /* non diegetic panning gain*/ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ + int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ + int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ #ifdef DEBUGGING /* temp. development parameters */ int16_t force_rend; /* forced TD/CLDFB binaural renderer (for ISM and MC) */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index aeb8f84303..9943fb4f37 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -38,6 +38,7 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" +#include "ambi_convert.h" #include #include #include @@ -383,6 +384,10 @@ ivas_error IVAS_DEC_Configure( const int16_t Opt_dpid_on, /* i : enable directivity pattern option */ const uint16_t acousticEnvironmentId, /* i : Acoustic environment ID */ const int16_t delayCompensationEnabled /* i : enable delay compensation */ +#ifdef AMBISONICS_CONVENTIONS + , + const AMBI_FMT sba_output_fmt +#endif ) { Decoder_Struct *st_ivas; @@ -423,6 +428,9 @@ ivas_error IVAS_DEC_Configure( st_ivas->element_mode_init = EVS_MONO; hDecoderConfig->nchan_out = 1; } +#ifdef AMBISONICS_CONVENTIONS + hDecoderConfig->sba_output_fmt = sba_output_fmt; +#endif if ( outputConfig != IVAS_AUDIO_CONFIG_EXTERNAL && outputConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 2dccb45525..9bedeb773f 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -137,6 +137,10 @@ ivas_error IVAS_DEC_Configure( const int16_t Opt_dpid_on, /* i : enable directivity pattern option */ const uint16_t acousticEnvironmentId, /* i : Acoustic environment ID */ const int16_t delayCompensationEnabled /* i : enable delay compensation */ +#ifdef AMBISONICS_CONVENTIONS + , + const AMBI_FMT sba_output_fmt +#endif ); void IVAS_DEC_Close( diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index f92a598afb..5118765deb 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -37,6 +37,7 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" +#include "ambi_convert.h" #include "stat_enc.h" #include "ivas_stat_com.h" @@ -1182,14 +1183,13 @@ typedef struct encoder_config_structure int16_t sba_planar; /* Ambisonic (SBA) planar flag */ MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ int16_t ism_extended_metadata_flag; /* flag indicating extended metadata encoding, including radius and orientation (yaw, pitch) in ISM format */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ int16_t Opt_DTX_ON; /* flag indicating DTX operation */ int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ #ifdef AMBISONICS_CONVENTIONS - int16_t sba_input_fmt; + AMBI_FMT sba_input_fmt; #endif int16_t Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 9bc0bb5d86..f789d4f18d 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -30,6 +30,9 @@ *******************************************************************************************************/ +#ifndef AMBI_CONVERT_H +#define AMBI_CONVERT_H + #include typedef enum @@ -61,3 +64,5 @@ int16_t convert_ambi_format( float* in[], float* out[], int16_t order, AMBI_FMT int16_t renormalize_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); int16_t reorder_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); + +#endif \ No newline at end of file -- GitLab From 254ca1e575f60d54f49d599086e9be19ebbeef84 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 19 Mar 2024 14:15:05 +0100 Subject: [PATCH 016/102] fix compile errors --- Workspace_msvc/lib_com.vcxproj | 4 ++-- apps/decoder.c | 2 +- lib_dec/lib_dec.h | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index d11b9087ee..8312a63fa5 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -59,7 +59,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_util;..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -308,4 +308,4 @@ - + \ No newline at end of file diff --git a/apps/decoder.c b/apps/decoder.c index 3114484255..998f814aa2 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1272,7 +1272,7 @@ static bool parseCmdlIVAS_dec( arg->sba_output_fmt = AMBI_FMT_ACN_SN3D; /* SBA configuration */ - if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) + if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%hd", &tmp ) > 0 ) { i++; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 9bedeb773f..dc7b7dffe8 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -34,6 +34,9 @@ #define LIB_DEC_H #include "common_api_types.h" +#ifdef AMBISONICS_CONVENTIONS +#include "ambi_convert.h" +#endif #include /*---------------------------------------------------------------------* -- GitLab From ac2ef780b43f8175c0774a3e6a6fce33528e3ac5 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 19 Mar 2024 14:58:06 +0100 Subject: [PATCH 017/102] implement output conversion for SBA format --- apps/decoder.c | 2 +- lib_dec/ivas_sba_dec.c | 13 +++++++++++++ lib_dec/ivas_spar_decoder.c | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 998f814aa2..b9ec69f6f1 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1279,7 +1279,7 @@ static bool parseCmdlIVAS_dec( else { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number!\n\n" ); + fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number!\n\n" ); usage_dec(); return false; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index af102dd96e..9628f7f47a 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -840,6 +840,19 @@ ivas_error ivas_sba_dec_render( } } +#ifdef AMBISONICS_CONVENTIONS + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 + ) + { + if ( st_ivas->hDecoderConfig->sba_output_fmt != 0 ) + { + convert_ambi_format( output_f, output_f, st_ivas->sba_analysis_order, AMBI_FMT_ACN_SN3D, st_ivas->hDecoderConfig->sba_output_fmt ); + } + } +#endif + if ( st_ivas->hDirAC != NULL && hSpar->slots_rendered == hSpar->num_slots ) { if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 2e0f4ae0eb..533949fd6c 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1717,6 +1717,7 @@ void ivas_spar_dec_upmixer_sf( ivas_spar_dump_signal_wav( output_frame, NULL, output, hSpar->numOutChannels, spar_foa_dec_wav[3], "cldfbSynthesis()" ); #endif + hSpar->slots_rendered += hSpar->subframe_nbslots[hSpar->subframes_rendered]; hSpar->subframes_rendered++; -- GitLab From cbaa644e0c483ee5a02a66ca79b60b9a8ca5e922 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 19 Mar 2024 15:53:39 +0100 Subject: [PATCH 018/102] fix formatting --- apps/decoder.c | 6 +++--- lib_dec/ivas_sba_dec.c | 7 +++---- lib_dec/lib_dec.c | 4 ++-- lib_util/ambi_convert.h | 6 +++--- scripts/check-format.sh | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b9ec69f6f1..706aa39346 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -444,7 +444,7 @@ int main( , arg.sba_output_fmt #endif - ) ) != IVAS_ERR_OK ) + ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -1773,7 +1773,7 @@ static void usage_dec( void ) static int16_t app_own_random( int16_t *seed ) { - *seed = ( int16_t )( *seed * 31821L + 13849L ); + *seed = (int16_t) ( *seed * 31821L + 13849L ); return ( *seed ); } @@ -3244,7 +3244,7 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == ( uint32_t )( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) { break; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9628f7f47a..c4efaa1bc8 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -841,10 +841,9 @@ ivas_error ivas_sba_dec_render( } #ifdef AMBISONICS_CONVENTIONS - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 - ) + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || + st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) { if ( st_ivas->hDecoderConfig->sba_output_fmt != 0 ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9943fb4f37..58eac4e99e 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -385,8 +385,8 @@ ivas_error IVAS_DEC_Configure( const uint16_t acousticEnvironmentId, /* i : Acoustic environment ID */ const int16_t delayCompensationEnabled /* i : enable delay compensation */ #ifdef AMBISONICS_CONVENTIONS - , - const AMBI_FMT sba_output_fmt + , + const AMBI_FMT sba_output_fmt #endif ) { diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index f789d4f18d..1848a218b4 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -59,10 +59,10 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; -int16_t convert_ambi_format( float* in[], float* out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); +int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); -int16_t renormalize_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); +int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); -int16_t reorder_channels( float* in[], float* out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); +int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); #endif \ No newline at end of file diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 154349de9f..079a1ed334 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -38,7 +38,7 @@ if [ ! -d "lib_com" ]; then exit 255 fi -CLANG_FORMAT=./clang-format.exe +CLANG_FORMAT=clang-format CLANG_FORMAT_REQUIRED_VERSION="13.0" # list (with space between entries) of substrings that are excluded from the file list, e.g. very large files -- GitLab From 8aff9db964d63f36b6d7819f8c3ab5b02bde7485 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 09:05:24 +0100 Subject: [PATCH 019/102] fix formatting --- lib_util/ambi_convert.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 1848a218b4..538cc5bbce 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -65,4 +65,5 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); -#endif \ No newline at end of file +#endif + -- GitLab From 2aee653eb1be7d4f3877c1eea2071289035a8b44 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 09:44:19 +0100 Subject: [PATCH 020/102] fix cmake build errors --- CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b96aa88d11..0267f6cc4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,7 +138,7 @@ add_library(lib_com ${libComSrcs} ${libComHeaders}) if(UNIX) target_link_libraries(lib_com PRIVATE m) endif() -target_include_directories(lib_com PUBLIC lib_com PRIVATE lib_enc lib_dec lib_rend lib_debug) +target_include_directories(lib_com PUBLIC lib_com PRIVATE lib_enc lib_dec lib_rend lib_debug lib_util) if(INCLUDE_SPLIT) target_include_directories(lib_com PRIVATE lib_lc3plus) endif() @@ -147,13 +147,13 @@ file(GLOB libDebugSrcs "lib_debug/*.c") file(GLOB libDebugHeaders "lib_debug/*.h") add_library(lib_debug ${libDebugSrcs} ${libDebugHeaders}) target_link_libraries(lib_debug lib_com) -target_include_directories(lib_debug PUBLIC lib_debug PRIVATE lib_enc lib_dec lib_rend) +target_include_directories(lib_debug PUBLIC lib_debug PRIVATE lib_enc lib_dec lib_rend lib_util) file(GLOB libEncSrcs "lib_enc/*.c") file(GLOB libEncHeaders "lib_enc/*.h") add_library(lib_enc ${libEncSrcs} ${libEncHeaders}) target_link_libraries(lib_enc lib_com lib_debug) -target_include_directories(lib_enc PUBLIC lib_enc PRIVATE lib_dec lib_rend) +target_include_directories(lib_enc PUBLIC lib_enc PRIVATE lib_dec lib_rend lib_util ) if(INCLUDE_SPLIT) target_include_directories(lib_enc PRIVATE lib_lc3plus) endif() @@ -188,18 +188,18 @@ if(NOT INCLUDE_SPLIT) endif() add_library(lib_rend ${libRendSrcs} ${libRendHeaders}) -target_link_libraries(lib_rend lib_dec lib_com lib_debug) # Todo refactor: This dependency on lib_dec should be removed. +target_link_libraries(lib_rend lib_dec lib_com lib_debug lib_util) # Todo refactor: This dependency on lib_dec should be removed. if(INCLUDE_SPLIT) target_link_libraries(lib_rend lib_lc3plus) endif() -target_include_directories(lib_rend PUBLIC lib_rend PRIVATE lib_enc) +target_include_directories(lib_rend PUBLIC lib_rend PRIVATE lib_enc lib_util) file(GLOB libDecSrcs "lib_dec/*.c") file(GLOB libDecHeaders "lib_dec/*.h") add_library(lib_dec ${libDecSrcs} ${libDecHeaders}) target_link_libraries(lib_dec lib_com lib_rend lib_debug) -target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_enc) +target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_enc lib_util) file(GLOB libUtilSrcs "lib_util/*.c") file(GLOB libUtilHeaders "lib_util/*.h") @@ -207,7 +207,7 @@ if(NOT INCLUDE_SPLIT) list(FILTER libUtilSrcs EXCLUDE REGEX ".*lib_util\/.*split_rend.*\.c$") endif() add_library(lib_util ${libUtilSrcs} ${libUtilHeaders}) -target_include_directories(lib_util PUBLIC lib_util PRIVATE lib_com lib_enc lib_dec lib_rend lib_debug) +target_include_directories(lib_util PUBLIC lib_util PRIVATE lib_com lib_enc lib_dec lib_rend lib_debug lib_util) if(INCLUDE_SPLIT) target_include_directories(lib_util PRIVATE lib_lc3plus) endif() @@ -233,7 +233,7 @@ endif() add_executable(IVAS_rend apps/renderer.c) target_link_libraries(IVAS_rend lib_rend lib_util) -target_include_directories(IVAS_rend PRIVATE lib_enc) +target_include_directories(IVAS_rend PRIVATE lib_enc lib_util) if(COPY_EXECUTABLES_FROM_BUILD_DIR) # Optionally copy executables to the same place where Make puts them (useful for tests that expect executables in specific places) -- GitLab From 30ed7f00b266032b25d9b3a4b9b6a1fd1fc7d090 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 10:27:17 +0100 Subject: [PATCH 021/102] add missing conversions --- lib_util/ambi_convert.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8a6461d51f..8a7af6b078 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -71,6 +71,8 @@ static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; + + static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, @@ -81,15 +83,16 @@ static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, - 1.0f, 1.0f, 1.0f, - TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, - SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; -static const float FM_MAXN[AMBI_MAX_CHANNELS] = { INV_SQRT_2, - 1.0f, 1.0f, 1.0f, - INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, - INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; +static const float SN3D_FM[AMBI_MAX_CHANNELS] = { SQRT_2_, + 1.0f, 1.0f, 1.0f, + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; + +static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, + 1.0f, 1.0f, 1.0f, + INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, + INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; /* ---------------------------- channel re-ordering tables @@ -199,6 +202,10 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = SN3D_MAXN; } + else if ( out_format == AMBI_NORM_FM ) + { + conversion_table = SN3D_FM; + } else { assert( 0 && "Unsupported conversion" ); @@ -214,6 +221,10 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = MAXN_SN3D; } + else if ( in_format == AMBI_NORM_FM ) + { + conversion_table = FM_SN3D; + } else { assert( 0 && "Unsupported conversion" ); @@ -262,11 +273,11 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL { if ( in_format == AMBI_CHANNEL_ORDER_FM ) { - idx_table = REORDER_ACN_FM; + idx_table = REORDER_FM_ACN; } if ( in_format == AMBI_CHANNEL_ORDER_SID ) { - idx_table = REORDER_ACN_SID; + idx_table = REORDER_SID_ACN; } else { -- GitLab From b053ae95032a3af7f9198fe7fff14697a9c59b69 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 10:35:24 +0100 Subject: [PATCH 022/102] fix formatting --- lib_util/ambi_convert.c | 23 +++++++++++------------ lib_util/ambi_convert.h | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8a7af6b078..d804e1079d 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -72,7 +72,6 @@ static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; - static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, @@ -84,15 +83,15 @@ static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -static const float SN3D_FM[AMBI_MAX_CHANNELS] = { SQRT_2_, - 1.0f, 1.0f, 1.0f, - TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, - SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; +static const float SN3D_FM[AMBI_MAX_CHANNELS] = { SQRT_2_, + 1.0f, 1.0f, 1.0f, + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; -static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, - 1.0f, 1.0f, 1.0f, - INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, - INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; +static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, + 1.0f, 1.0f, 1.0f, + INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, + INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; /* ---------------------------- channel re-ordering tables @@ -202,10 +201,10 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = SN3D_MAXN; } - else if ( out_format == AMBI_NORM_FM ) - { + else if ( out_format == AMBI_NORM_FM ) + { conversion_table = SN3D_FM; - } + } else { assert( 0 && "Unsupported conversion" ); diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 538cc5bbce..b326dc4499 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -66,4 +66,3 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); #endif - -- GitLab From c6f168806d0093b328059df8af38918c45376637 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 16:51:22 +0100 Subject: [PATCH 023/102] fix uninitialized variable in decoder command line arguments --- apps/decoder.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 706aa39346..3b6f03b6cf 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1085,6 +1085,10 @@ static bool parseCmdlIVAS_dec( arg->renderConfigFilename = NULL; arg->Opt_dpid_on = 0; +#ifdef AMBISONICS_CONVENTIONS + arg->sba_output_fmt = AMBI_FMT_ACN_SN3D; +#endif + #ifdef SPLIT_REND_WITH_HEAD_ROT arg->outputMdFilename = NULL; #endif @@ -1773,7 +1777,7 @@ static void usage_dec( void ) static int16_t app_own_random( int16_t *seed ) { - *seed = (int16_t) ( *seed * 31821L + 13849L ); + *seed = ( int16_t )( *seed * 31821L + 13849L ); return ( *seed ); } @@ -3244,7 +3248,7 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + if ( nextPacketRcvTime_ms == ( uint32_t )( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) { break; } -- GitLab From d705d8a9ec176aebd6a757e52b8eefc7dd31820a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 20 Mar 2024 16:59:15 +0100 Subject: [PATCH 024/102] fix formatting --- apps/decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 3b6f03b6cf..db0eec6a8d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1777,7 +1777,7 @@ static void usage_dec( void ) static int16_t app_own_random( int16_t *seed ) { - *seed = ( int16_t )( *seed * 31821L + 13849L ); + *seed = (int16_t) ( *seed * 31821L + 13849L ); return ( *seed ); } @@ -3248,7 +3248,7 @@ static ivas_error decodeVoIP( /* we are finished when all packets have been received and jitter buffer is empty */ /* also stop when the input file contains less than two frames, because JBM cannot calculate a delay value and won't start decoding */ /* last clause should make sure that for BE tests we end up with the same number of samples...*/ - if ( nextPacketRcvTime_ms == ( uint32_t )( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) + if ( nextPacketRcvTime_ms == (uint32_t) ( -1 ) && ( IVAS_DEC_VoIP_IsEmpty( hIvasDec, nOutSamples ) || nFramesFed < 2 ) ) { break; } -- GitLab From 28b7306fc3f92f7609d966423c755dd50eb74e63 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 21 Mar 2024 08:55:58 +0100 Subject: [PATCH 025/102] fix uninitialized value in the arguments structure in the encoder --- apps/encoder.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 68373f2c3e..948ed28372 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -61,8 +61,7 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig -{ +typedef union _EncInputFormatConfig { /* MONO details */ bool stereoToMonoDownmix; @@ -894,6 +893,9 @@ static void initArgStruct( EncArguments *arg ) arg->outputBitstreamFilename = NULL; arg->inputFs = 0; arg->inputFormat = IVAS_ENC_INPUT_MONO; +#ifdef AMBISONICS_CONVENTIONS + arg->sba_input_fmt = AMBI_FMT_ACN_SN3D; +#endif arg->is_binaural = false; arg->inputFormatConfig.stereoToMonoDownmix = false; arg->max_bwidth_user = false; @@ -926,6 +928,8 @@ static void initArgStruct( EncArguments *arg ) #endif arg->pca = false; + + return; } -- GitLab From e883a27e0bdc623105c92479328b4f4f4a268661 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 21 Mar 2024 08:57:08 +0100 Subject: [PATCH 026/102] fix formatting --- apps/encoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 948ed28372..8a4ac80608 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -61,7 +61,8 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig { +typedef union _EncInputFormatConfig +{ /* MONO details */ bool stereoToMonoDownmix; @@ -929,7 +930,6 @@ static void initArgStruct( EncArguments *arg ) arg->pca = false; - return; } -- GitLab From edd731083a6f3e2f3839bb0801ef7c4188969742 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 27 Mar 2024 13:40:14 +0100 Subject: [PATCH 027/102] add conversion tables for AmbiX convention --- lib_util/ambi_convert.c | 36 ++++++++++++++++++++++++++++++++++++ lib_util/ambi_convert.h | 10 ++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index d804e1079d..d99472d991 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -55,6 +55,9 @@ #define INV_SQRT_3_OVER_5_ 1.2909944f #define INV_SQRT_45_OVER_32_ 0.8432740f +#define INV_SQRT_FOUR_PI_ 0.2820947f /* 1/sqrt(4/pi) */ +#define SQRT_FOUR_PI_ 3.5449077f + #define AMBI_MAX_CHANNELS 16 /* -------------------------------- @@ -93,6 +96,23 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; +/* + Curiously, not everyone seems to have the same understanding of what SN3D means. The Ambix paper + (Nachbar et al. : AMBIX - A SUGGESTED AMBISONICS FORMAT) has an additional 1/sqrt(4*pi) in the + normalization factor (see Eq. (3)) as compared to the tables in IVAS. +*/ + +static const float AMBIX_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_FOUR_PI_, + INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, + INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, + INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_ }; + +static const float SN3D_AMBIX[AMBI_MAX_CHANNELS] = { SQRT_FOUR_PI_, + SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, + SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, + SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_ }; + + /* ---------------------------- channel re-ordering tables ---------------------------- */ @@ -136,6 +156,10 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_MAXN ); reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); } + else if ( out_format == AMBI_FMT_AMBIX ) + { + renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_AMBIX ); + } else if ( out_format == AMBI_FMT_SID_SN3D ) { reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); @@ -161,6 +185,10 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_FM, AMBI_CHANNEL_ORDER_ACN ); renormalize_channels( in, out, order, AMBI_NORM_MAXN, AMBI_NORM_SN3D ); } + else if ( in_format == AMBI_FMT_AMBIX ) + { + renormalize_channels( in, out, order, AMBI_NORM_AMBIX, AMBI_NORM_SN3D ); + } else if ( in_format == AMBI_FMT_SID_SN3D ) { reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); @@ -201,6 +229,10 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = SN3D_MAXN; } + else if ( out_format == AMBI_NORM_AMBIX ) + { + conversion_table = SN3D_AMBIX; + } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; @@ -220,6 +252,10 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = MAXN_SN3D; } + if ( in_format == AMBI_NORM_AMBIX ) + { + conversion_table = AMBIX_SN3D; + } else if ( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index b326dc4499..8e04212013 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -38,16 +38,18 @@ typedef enum { AMBI_FMT_ACN_SN3D = 0, - AMBI_FMT_ACN_N3D = 1, - AMBI_FMT_FM_MAXN = 2, - AMBI_FMT_SID_SN3D = 3, - AMBI_FMT_SID_N3D = 4 + AMBI_FMT_ACN_N3D, + AMBI_FMT_AMBIX, + AMBI_FMT_FM_MAXN, + AMBI_FMT_SID_SN3D, + AMBI_FMT_SID_N3D } AMBI_FMT; typedef enum { AMBI_NORM_SN3D = 0, AMBI_NORM_N3D, + AMBI_NORM_AMBIX, AMBI_NORM_MAXN, AMBI_NORM_FM } AMBI_CHANNEL_NORM; -- GitLab From f31ae5ffe2d5e4e5306cb56a31e2791c473ec5fc Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 27 Mar 2024 13:46:56 +0100 Subject: [PATCH 028/102] explain ambisonics conventions in usage_enc/dec --- apps/decoder.c | 4 ++++ apps/encoder.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index db0eec6a8d..c4c38e8640 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1688,6 +1688,10 @@ static void usage_dec( void ) #else fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, EXT\n" ); +#endif +#ifdef AMBISONICS_CONVENTIONS + fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); #endif fprintf( stdout, " By default, channel order and loudspeaker positions are equal to the\n" ); fprintf( stdout, " encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker\n" ); diff --git a/apps/encoder.c b/apps/encoder.c index 8a4ac80608..6dfa5472ce 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -61,8 +61,7 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig -{ +typedef union _EncInputFormatConfig { /* MONO details */ bool stereoToMonoDownmix; @@ -1900,6 +1899,10 @@ static void usage_enc( void ) fprintf( stdout, "-sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D),\n" ); fprintf( stdout, " where Order specifies the Ambisionics order (1-3),\n" ); fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); +#ifdef AMBISONICS_CONVENTIONS + fprintf( stdout, "-sba_convention n : Ambisonics convention of the input signal" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); +#endif fprintf( stdout, "-masa Ch File : MASA format \n" ); fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); fprintf( stdout, " and File specifies input file containing parametric MASA metadata \n" ); -- GitLab From b3671fada72a42597a31162ea2326d30b0f1ec1b Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 27 Mar 2024 14:00:01 +0100 Subject: [PATCH 029/102] fix formatting --- apps/encoder.c | 3 ++- lib_util/ambi_convert.c | 10 +++++----- lib_util/ambi_convert.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 6dfa5472ce..047faaaea8 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -61,7 +61,8 @@ static #define DEFAULT_FIXED_SID_RATE 8 /* DTX SID rate */ /* Additional config info for each input format */ -typedef union _EncInputFormatConfig { +typedef union _EncInputFormatConfig +{ /* MONO details */ bool stereoToMonoDownmix; diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index d99472d991..487491b388 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -55,8 +55,8 @@ #define INV_SQRT_3_OVER_5_ 1.2909944f #define INV_SQRT_45_OVER_32_ 0.8432740f -#define INV_SQRT_FOUR_PI_ 0.2820947f /* 1/sqrt(4/pi) */ -#define SQRT_FOUR_PI_ 3.5449077f +#define INV_SQRT_FOUR_PI_ 0.2820947f /* 1/sqrt(4/pi) */ +#define SQRT_FOUR_PI_ 3.5449077f #define AMBI_MAX_CHANNELS 16 @@ -96,9 +96,9 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -/* - Curiously, not everyone seems to have the same understanding of what SN3D means. The Ambix paper - (Nachbar et al. : AMBIX - A SUGGESTED AMBISONICS FORMAT) has an additional 1/sqrt(4*pi) in the +/* + Curiously, not everyone seems to have the same understanding of what SN3D means. The Ambix paper + (Nachbar et al. : AMBIX - A SUGGESTED AMBISONICS FORMAT) has an additional 1/sqrt(4*pi) in the normalization factor (see Eq. (3)) as compared to the tables in IVAS. */ diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 8e04212013..591194a06c 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -49,7 +49,7 @@ typedef enum { AMBI_NORM_SN3D = 0, AMBI_NORM_N3D, - AMBI_NORM_AMBIX, + AMBI_NORM_AMBIX, AMBI_NORM_MAXN, AMBI_NORM_FM } AMBI_CHANNEL_NORM; -- GitLab From df137ff081fe55fc8294b675c562ea0f4867b2a9 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 27 Mar 2024 15:38:47 +0100 Subject: [PATCH 030/102] update readme.txt and README.md --- README.md | 2 +- readme.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 899e52ddc1..836d130196 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -please refer to the [Wiki](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/home) +please refer to the [Wiki](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/home). For the Ambisonics conventions see [here](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/Ambisonics-conventions). diff --git a/readme.txt b/readme.txt index 25275a7951..0cdb7ddaaf 100644 --- a/readme.txt +++ b/readme.txt @@ -191,6 +191,8 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D), where Order specifies the Ambisionics order (1-3), where positive (+) means full 3D and negative (-) only 2D/planar components to be coded +-sba_convention n : Ambisonics convention of the input signal + where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D) -masa Ch File : MASA format where Ch specifies the number of MASA input/transport channels (1 or 2): and File specifies input file containing parametric MASA metadata @@ -250,6 +252,8 @@ output_file : Output audio filename Options: -------- +-sba_convention n : Ambisonics convention of the output signal + where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D) -VOIP : VoIP mode: RTP in G192 -VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump -VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump -- GitLab From f237cc7b57fdb1146c4aff46cce587fa06150c91 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 27 Mar 2024 17:17:48 +0100 Subject: [PATCH 031/102] fix usage_dec message --- apps/decoder.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index c4c38e8640..d3f6f8bcc3 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1688,10 +1688,6 @@ static void usage_dec( void ) #else fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, EXT\n" ); -#endif -#ifdef AMBISONICS_CONVENTIONS - fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); #endif fprintf( stdout, " By default, channel order and loudspeaker positions are equal to the\n" ); fprintf( stdout, " encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker\n" ); @@ -1703,6 +1699,10 @@ static void usage_dec( void ) fprintf( stdout, "Options:\n" ); fprintf( stdout, "--------\n" ); +#ifdef AMBISONICS_CONVENTIONS + fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); +#endif fprintf( stdout, "-VOIP : VoIP mode: RTP in G192\n" ); fprintf( stdout, "-VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump\n" ); fprintf( stdout, "-VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump\n" ); -- GitLab From d4b187551c95ccb32795214a74ef1871f50e4833 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 10 Jun 2024 14:39:24 +0200 Subject: [PATCH 032/102] fix conversion direction in the tables --- lib_util/ambi_convert.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 487491b388..2cefa3a11f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -64,34 +64,34 @@ normalization conversion tables -------------------------------- */ -static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, +static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, SQRT_3_, SQRT_3_, SQRT_3_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_5_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_, SQRT_7_ }; -static const float SN3D_N3D[AMBI_MAX_CHANNELS] = { 1.0f, +static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_3_, INV_SQRT_3_, INV_SQRT_3_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; -static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, +static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; -static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, +static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -static const float SN3D_FM[AMBI_MAX_CHANNELS] = { SQRT_2_, +static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; -static const float FM_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_2, +static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, 1.0f, 1.0f, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -- GitLab From e5c322970a00564f9988f5d93952a0303177f3b6 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 10 Jun 2024 15:25:45 +0200 Subject: [PATCH 033/102] fix build errors with cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b400a28027..abc646562b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,7 @@ file(GLOB libISARHeaders "lib_isar/*.h") add_library(lib_isar ${libISARSrcs} ${libISARHeaders}) target_link_libraries(lib_isar lib_com lib_debug lib_lc3plus) # Todo refactor: This dependency on lib_dec should be removed. -target_include_directories(lib_isar PUBLIC lib_isar PRIVATE lib_enc lib_dec lib_rend) +target_include_directories(lib_isar PUBLIC lib_isar PRIVATE lib_enc lib_dec lib_rend lib_util) add_executable(IVAS_cod apps/encoder.c) -- GitLab From a4acf15bed27c71c422ee7166af08a00e90e7def Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 10 Jun 2024 16:06:17 +0200 Subject: [PATCH 034/102] remove trivial conversion AMBIX<->SN3D --- lib_util/ambi_convert.c | 33 --------------------------------- lib_util/ambi_convert.h | 1 - 2 files changed, 34 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 2cefa3a11f..29298d37d4 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -96,23 +96,6 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; -/* - Curiously, not everyone seems to have the same understanding of what SN3D means. The Ambix paper - (Nachbar et al. : AMBIX - A SUGGESTED AMBISONICS FORMAT) has an additional 1/sqrt(4*pi) in the - normalization factor (see Eq. (3)) as compared to the tables in IVAS. -*/ - -static const float AMBIX_SN3D[AMBI_MAX_CHANNELS] = { INV_SQRT_FOUR_PI_, - INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, - INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, - INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_, INV_SQRT_FOUR_PI_ }; - -static const float SN3D_AMBIX[AMBI_MAX_CHANNELS] = { SQRT_FOUR_PI_, - SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, - SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, - SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_, SQRT_FOUR_PI_ }; - - /* ---------------------------- channel re-ordering tables ---------------------------- */ @@ -156,10 +139,6 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_MAXN ); reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); } - else if ( out_format == AMBI_FMT_AMBIX ) - { - renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_AMBIX ); - } else if ( out_format == AMBI_FMT_SID_SN3D ) { reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); @@ -185,10 +164,6 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_FM, AMBI_CHANNEL_ORDER_ACN ); renormalize_channels( in, out, order, AMBI_NORM_MAXN, AMBI_NORM_SN3D ); } - else if ( in_format == AMBI_FMT_AMBIX ) - { - renormalize_channels( in, out, order, AMBI_NORM_AMBIX, AMBI_NORM_SN3D ); - } else if ( in_format == AMBI_FMT_SID_SN3D ) { reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); @@ -229,10 +204,6 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = SN3D_MAXN; } - else if ( out_format == AMBI_NORM_AMBIX ) - { - conversion_table = SN3D_AMBIX; - } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; @@ -252,10 +223,6 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = MAXN_SN3D; } - if ( in_format == AMBI_NORM_AMBIX ) - { - conversion_table = AMBIX_SN3D; - } else if ( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 591194a06c..2508b59307 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -49,7 +49,6 @@ typedef enum { AMBI_NORM_SN3D = 0, AMBI_NORM_N3D, - AMBI_NORM_AMBIX, AMBI_NORM_MAXN, AMBI_NORM_FM } AMBI_CHANNEL_NORM; -- GitLab From 924b0803c367b5733fec1a2398594256520f9231 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 11 Jun 2024 15:36:17 +0200 Subject: [PATCH 035/102] fix command line parsing and add a check for a meaningful argument --- apps/decoder.c | 4 ++-- apps/encoder.c | 11 +++++++++-- lib_util/ambi_convert.h | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9cb609e539..6399263754 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1726,8 +1726,8 @@ static void usage_dec( void ) fprintf( stdout, "Options:\n" ); fprintf( stdout, "--------\n" ); #ifdef AMBISONICS_CONVENTIONS - fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); + fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D)" ); #endif fprintf( stdout, "-VOIP : VoIP mode: RTP in G192\n" ); fprintf( stdout, "-VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump\n" ); diff --git a/apps/encoder.c b/apps/encoder.c index 047faaaea8..ce5a55fe61 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1219,11 +1219,18 @@ static bool parseCmdlIVAS_enc( else { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number!\n\n" ); + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); usage_enc(); return false; } - arg->sba_input_fmt = tmp; + if( tmp < 0 || tmp > 4 ) + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf(stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n"); + usage_enc(); + return false; + } + arg->sba_input_fmt = tmp; } #endif diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 2508b59307..05aea37881 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -39,7 +39,6 @@ typedef enum { AMBI_FMT_ACN_SN3D = 0, AMBI_FMT_ACN_N3D, - AMBI_FMT_AMBIX, AMBI_FMT_FM_MAXN, AMBI_FMT_SID_SN3D, AMBI_FMT_SID_N3D -- GitLab From 794160673ead3fec1cb00d92a08b448be298f73f Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 11 Jun 2024 16:06:44 +0200 Subject: [PATCH 036/102] fix argument type in function IVAS_ENC_ConfigureForAmbisonics --- lib_enc/lib_enc.c | 6 +++--- lib_enc/lib_enc.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 68b37bab7d..cb598c074f 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -485,16 +485,16 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ + const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ #endif - const bool Opt_PCA_ON /* i : PCA option flag */ + const bool Opt_PCA_ON /* i : PCA option flag */ #ifdef DEBUG_SBA_AUDIO_DUMP , int16_t *numTransportChannels #endif #ifdef AMBISONICS_CONVENTIONS , - const int16_t sba_input_fmt + AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ #endif ) { diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 58860e3107..1ad4f15d6c 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -249,7 +249,7 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( #endif #ifdef AMBISONICS_CONVENTIONS , - const int16_t sba_input_fmt + AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ #endif ); -- GitLab From 73207853688ded55ab0ce8f563e20051a041bb97 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 11 Jun 2024 16:08:10 +0200 Subject: [PATCH 037/102] remove unnecessary constant --- lib_util/ambi_convert.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 29298d37d4..ea2ff355e6 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -56,7 +56,6 @@ #define INV_SQRT_45_OVER_32_ 0.8432740f #define INV_SQRT_FOUR_PI_ 0.2820947f /* 1/sqrt(4/pi) */ -#define SQRT_FOUR_PI_ 3.5449077f #define AMBI_MAX_CHANNELS 16 -- GitLab From 32e5bb36ea4d7a05c3d0afd3662b888960eb8133 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 11 Jun 2024 16:13:13 +0200 Subject: [PATCH 038/102] fix formatting --- apps/encoder.c | 16 ++++++++-------- lib_enc/lib_enc.c | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index ce5a55fe61..7600a23d5e 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1223,14 +1223,14 @@ static bool parseCmdlIVAS_enc( usage_enc(); return false; } - if( tmp < 0 || tmp > 4 ) - { - tmp = -1; /* this is to avoid a compilation warning */ - fprintf(stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n"); - usage_enc(); - return false; - } - arg->sba_input_fmt = tmp; + if ( tmp < 0 || tmp > 4 ) + { + tmp = -1; /* this is to avoid a compilation warning */ + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); + usage_enc(); + return false; + } + arg->sba_input_fmt = tmp; } #endif diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index cb598c074f..84f9fe2421 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -485,16 +485,16 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ #ifdef DEBUG_AGC_ENCODER_CMD_OPTION - const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ + const IVAS_ENC_AGC Opt_AGC_ON, /* i : AGC on/off/undefined flag */ #endif - const bool Opt_PCA_ON /* i : PCA option flag */ + const bool Opt_PCA_ON /* i : PCA option flag */ #ifdef DEBUG_SBA_AUDIO_DUMP , int16_t *numTransportChannels #endif #ifdef AMBISONICS_CONVENTIONS , - AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ + AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ #endif ) { -- GitLab From 69c56ab38e06659ede1f646999563011ebf7515e Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 11 Jun 2024 16:30:15 +0200 Subject: [PATCH 039/102] fix compile errors --- lib_enc/lib_enc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 1ad4f15d6c..13177c7cb9 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -34,6 +34,9 @@ #define LIB_ENC_H #include "common_api_types.h" +#ifdef AMBISONICS_CONVENTIONS +#include "ambi_convert.h" +#endif #include -- GitLab From af85f142b9966e272d4b23a00c49ece7503dc8e1 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 11:34:34 +0200 Subject: [PATCH 040/102] fix usage_enc output --- apps/encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/encoder.c b/apps/encoder.c index 7600a23d5e..e063d7a7d7 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1909,7 +1909,7 @@ static void usage_enc( void ) fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); #ifdef AMBISONICS_CONVENTIONS fprintf( stdout, "-sba_convention n : Ambisonics convention of the input signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D)" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D)" ); #endif fprintf( stdout, "-masa Ch File : MASA format \n" ); fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); -- GitLab From 676ab6b65b7898a71d3b6f7084af85827ff4c481 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 11:38:05 +0200 Subject: [PATCH 041/102] add check for argument range to decoder command line parser --- apps/decoder.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6399263754..77a9138927 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1280,10 +1280,17 @@ static bool parseCmdlIVAS_dec( else { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number!\n\n" ); + fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number [0-4]!\n\n" ); usage_dec(); return false; } + if ( tmp < 0 || tmp > 4 ) + { + tmp = -1; + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); + usage_enc(); + return false; + } arg->sba_output_fmt = tmp; } #endif -- GitLab From 7aaf328a6539dd60f7e68b316aea20ff3adae622 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 11:56:03 +0200 Subject: [PATCH 042/102] fix compile error --- apps/decoder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 77a9138927..84ec71a32f 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1287,8 +1287,8 @@ static bool parseCmdlIVAS_dec( if ( tmp < 0 || tmp > 4 ) { tmp = -1; - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); - usage_enc(); + fprintf( stderr, "Error: SBA output convention must be specified, expecting a number in [0,4]!\n\n" ); + usage_dec(); return false; } arg->sba_output_fmt = tmp; -- GitLab From a253dffe488b353020c39559d877ef7851281871 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 11:56:24 +0200 Subject: [PATCH 043/102] update readme.txt --- readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index a50bc83c1e..92907bedfd 100644 --- a/readme.txt +++ b/readme.txt @@ -195,7 +195,7 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, where Order specifies the Ambisionics order (1-3), where positive (+) means full 3D and negative (-) only 2D/planar components to be coded -sba_convention n : Ambisonics convention of the input signal - where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D) + where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D) -masa Ch File : MASA format where Ch specifies the number of MASA input/transport channels (1 or 2): and File specifies input file containing parametric MASA metadata @@ -257,7 +257,7 @@ output_file : Output audio filename Options: -------- -sba_convention n : Ambisonics convention of the output signal - where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (AMBIX), 3 (FuMa-MaxN), 4 (SID-SN3D), 5 (SID-N3D) + where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D) -VOIP : VoIP mode: RTP in G192 -VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump -VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump -- GitLab From b958e6f09ff1955bac9727d59e2b9be5b173261d Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 12:26:40 +0200 Subject: [PATCH 044/102] always attenuate the signal when converting to SN3D --- lib_util/ambi_convert.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index ea2ff355e6..314cf2edea 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -59,6 +59,15 @@ #define AMBI_MAX_CHANNELS 16 +/* + For conversions to SN3D we want to avoid clipping the decoder input. + The GLOBAL_SCALING_FACTOR ensures that the amplitude is always attenuated. + The inverse INV_GLOBAL_SCALING_FACTOR restores the original amplitude when + converting back to the input convention after the decoding. +*/ +#define GLOBAL_SCALING_FACTOR 0.7071067f +#define INV_GLOBAL_SCALING_FACTOR 0.7071067f + /* -------------------------------- normalization conversion tables -------------------------------- */ @@ -236,12 +245,26 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + if ( out_format == AMBI_NORM_SN3D ) + { + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + float conversion_factor = conversion_table[i_chan]; + for ( i = 0; i < L_FRAME48k; i++ ) + { + out[i_chan][i] = GLOBAL_SCALING_FACTOR * in[i_chan][i] * conversion_factor; + } + } + } + else { - float conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { - out[i_chan][i] = in[i_chan][i] * conversion_factor; + float conversion_factor = conversion_table[i_chan]; + for ( i = 0; i < L_FRAME48k; i++ ) + { + out[i_chan][i] = INV_GLOBAL_SCALING_FACTOR * in[i_chan][i] * conversion_factor; + } } } -- GitLab From 1f9fadfc557dc48182fdab3ee0df423f3b629524 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 12:44:35 +0200 Subject: [PATCH 045/102] do rescaling for each conversion individually --- lib_util/ambi_convert.c | 47 +++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 314cf2edea..e5cdb4125a 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -55,18 +55,8 @@ #define INV_SQRT_3_OVER_5_ 1.2909944f #define INV_SQRT_45_OVER_32_ 0.8432740f -#define INV_SQRT_FOUR_PI_ 0.2820947f /* 1/sqrt(4/pi) */ - #define AMBI_MAX_CHANNELS 16 -/* - For conversions to SN3D we want to avoid clipping the decoder input. - The GLOBAL_SCALING_FACTOR ensures that the amplitude is always attenuated. - The inverse INV_GLOBAL_SCALING_FACTOR restores the original amplitude when - converting back to the input convention after the decoding. -*/ -#define GLOBAL_SCALING_FACTOR 0.7071067f -#define INV_GLOBAL_SCALING_FACTOR 0.7071067f /* -------------------------------- normalization conversion tables @@ -82,6 +72,8 @@ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; +static const float N3D_SCALING_FACTOR = 1.0f; + static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, @@ -93,6 +85,8 @@ static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; +static const float MAXN_SCALING_FACTOR = SQRT_3_OVER_5_; + static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, 1.0f, 1.0f, 1.0f, @@ -104,6 +98,9 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; +static const float FM_SCALING_FACTOR = INV_SQRT_2; + + /* ---------------------------- channel re-ordering tables ---------------------------- */ @@ -199,6 +196,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; const float *conversion_table = 0; + float sf = 1.0f; /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ @@ -207,14 +205,17 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; + sf = 1.f / N3D_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; + sf = 1.f / MAXN_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; + sf = 1.f / FM_SCALING_FACTOR; } else { @@ -226,14 +227,17 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; + sf = N3D_SCALING_FACTOR; } else if ( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; + sf = MAXN_SCALING_FACTOR; } else if ( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; + sf = FM_SCALING_FACTOR; } else { @@ -245,26 +249,13 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - if ( out_format == AMBI_NORM_SN3D ) - { - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) - { - float conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) - { - out[i_chan][i] = GLOBAL_SCALING_FACTOR * in[i_chan][i] * conversion_factor; - } - } - } - else + + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + float conversion_factor = conversion_table[i_chan]; + for ( i = 0; i < L_FRAME48k; i++ ) { - float conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) - { - out[i_chan][i] = INV_GLOBAL_SCALING_FACTOR * in[i_chan][i] * conversion_factor; - } + out[i_chan][i] = sf * in[i_chan][i] * conversion_factor; } } -- GitLab From fa80b6ace2eb2094e2da566dd560cf9060fe60e2 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 14:40:21 +0200 Subject: [PATCH 046/102] fix errors in MAXN and FuMa scaling tables --- lib_util/ambi_convert.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index e5cdb4125a..2e14c8a3e2 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -45,15 +45,15 @@ #define INV_SQRT_5_ 0.4472135f #define INV_SQRT_7_ 0.3779644f -#define TWO_OVER_SQRT_3_ 1.1547005f -#define SQRT_8_OVER_5_ 1.2649110f -#define SQRT_3_OVER_5_ 0.7745966f -#define SQRT_45_OVER_32_ 1.1858541f +#define TWO_OVER_SQRT_3_ 1.1547005f +#define THREE_OVER_SQRT_5_ 1.3416408f +#define SQRT_8_OVER_5_ 1.2649110f +#define SQRT_45_OVER_32_ 1.1858541f -#define INV_TWO_OVER_SQRT_3_ 0.8660254f -#define INV_SQRT_8_OVER_5_ 0.7905694f -#define INV_SQRT_3_OVER_5_ 1.2909944f -#define INV_SQRT_45_OVER_32_ 0.8432740f +#define INV_TWO_OVER_SQRT_3_ 0.8660254f +#define INV_THREE_OVER_SQRT_5_ 0.7453560f +#define INV_SQRT_8_OVER_5_ 0.7905694f +#define INV_SQRT_45_OVER_32_ 0.8432740f #define AMBI_MAX_CHANNELS 16 @@ -77,26 +77,26 @@ static const float N3D_SCALING_FACTOR = 1.0f; static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, - TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, - SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, THREE_OVER_SQRT_5_, SQRT_45_OVER_32_, 1.0f, SQRT_45_OVER_32_, THREE_OVER_SQRT_5_, SQRT_8_OVER_5_ }; static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, - INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; + INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float MAXN_SCALING_FACTOR = SQRT_3_OVER_5_; +static const float MAXN_SCALING_FACTOR = 1.0f; static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, 1.0f, 1.0f, 1.0f, - TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, - SQRT_8_OVER_5_, SQRT_3_OVER_5_, SQRT_45_OVER_32_, 1, SQRT_45_OVER_32_, SQRT_3_OVER_5_, SQRT_8_OVER_5_ }; + TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, + SQRT_8_OVER_5_, THREE_OVER_SQRT_5_, SQRT_45_OVER_32_, 1.0f, SQRT_45_OVER_32_, THREE_OVER_SQRT_5_, SQRT_8_OVER_5_ }; static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, 1.0f, 1.0f, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, - INV_SQRT_8_OVER_5_, INV_SQRT_3_OVER_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_SQRT_3_OVER_5_, INV_SQRT_8_OVER_5_ }; + INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; static const float FM_SCALING_FACTOR = INV_SQRT_2; -- GitLab From b5ee967dfc6c1c13b6f3cb8796c4b3ee4f8cf9c9 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 12 Jun 2024 17:14:08 +0200 Subject: [PATCH 047/102] wrap code in ib_util/ambi_convert.c into AMBISONICS_CONVENTIONS --- lib_util/ambi_convert.c | 3 +++ lib_util/ambi_convert.h | 1 + 2 files changed, 4 insertions(+) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 2e14c8a3e2..4da919a636 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -29,7 +29,9 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ +#include "options.h" +#ifdef AMBISONICS_CONVENTIONS #include #include #include "ivas_cnst.h" @@ -319,3 +321,4 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL return 0; } +#endif diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 05aea37881..d6db18a742 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -33,6 +33,7 @@ #ifndef AMBI_CONVERT_H #define AMBI_CONVERT_H +#include "options.h" #include typedef enum -- GitLab From aaa1cd10253580bb981a15d0d6f4be1332302e31 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 10:33:53 +0200 Subject: [PATCH 048/102] beautify code in convert_ambi_format --- lib_util/ambi_convert.c | 115 +++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 4da919a636..8af419b9c0 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -134,60 +134,79 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); + AMBI_CHANNEL_ORDER ch_ord_in = 0, ch_ord_out = 0; + AMBI_CHANNEL_NORM ch_norm_in = 0, ch_norm_out = 0; - if ( in_format == AMBI_FMT_ACN_SN3D ) + if ( in_format != AMBI_FMT_ACN_SN3D && out_format != AMBI_FMT_ACN_SN3D ) { - if ( out_format == AMBI_FMT_ACN_N3D ) - { - renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_N3D ); - } - else if ( out_format == AMBI_FMT_FM_MAXN ) - { - renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_MAXN ); - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_FM ); - } - else if ( out_format == AMBI_FMT_SID_SN3D ) - { - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); - } - else if ( out_format == AMBI_FMT_SID_N3D ) - { - renormalize_channels( in, out, order, AMBI_NORM_SN3D, AMBI_NORM_N3D ); - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_ACN, AMBI_CHANNEL_ORDER_SID ); - } - else - { - assert( 0 && "Unsupported conversion" ); - } + assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } - else if ( out_format == AMBI_FMT_ACN_SN3D ) + + switch ( in_format ) { - if ( in_format == AMBI_FMT_ACN_N3D ) - { - renormalize_channels( in, out, order, AMBI_NORM_N3D, AMBI_NORM_SN3D ); - } - else if ( in_format == AMBI_FMT_FM_MAXN ) - { - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_FM, AMBI_CHANNEL_ORDER_ACN ); - renormalize_channels( in, out, order, AMBI_NORM_MAXN, AMBI_NORM_SN3D ); - } - else if ( in_format == AMBI_FMT_SID_SN3D ) - { - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); - } - else if ( in_format == AMBI_FMT_SID_N3D ) - { - reorder_channels( in, out, order, AMBI_CHANNEL_ORDER_SID, AMBI_CHANNEL_ORDER_ACN ); - renormalize_channels( in, out, order, AMBI_NORM_N3D, AMBI_NORM_SN3D ); - } - else - { - assert( 0 && "Unsupported conversion" ); - } + case AMBI_FMT_ACN_SN3D: + ch_ord_in = AMBI_CHANNEL_ORDER_ACN; + ch_norm_in = AMBI_NORM_SN3D; + break; + case AMBI_FMT_ACN_N3D: + ch_ord_in = AMBI_CHANNEL_ORDER_ACN; + ch_norm_in = AMBI_NORM_N3D; + break; + case AMBI_FMT_FM_MAXN: + ch_ord_in = AMBI_CHANNEL_ORDER_FM; + ch_norm_in = AMBI_NORM_MAXN; + break; + case AMBI_FMT_SID_SN3D: + ch_ord_in = AMBI_CHANNEL_ORDER_SID; + ch_norm_in = AMBI_NORM_SN3D; + break; + case AMBI_FMT_SID_N3D: + ch_ord_in = AMBI_CHANNEL_ORDER_SID; + ch_norm_in = AMBI_NORM_N3D; + break; + default: + assert( 0 && "Unsupported in_format!" ); } - else + + switch ( out_format ) { - assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + case AMBI_FMT_ACN_SN3D: + ch_ord_out = AMBI_CHANNEL_ORDER_ACN; + ch_norm_out = AMBI_NORM_SN3D; + break; + case AMBI_FMT_ACN_N3D: + ch_ord_out = AMBI_CHANNEL_ORDER_ACN; + ch_norm_out = AMBI_NORM_N3D; + break; + case AMBI_FMT_FM_MAXN: + ch_ord_out = AMBI_CHANNEL_ORDER_FM; + ch_norm_in = AMBI_NORM_MAXN; + break; + case AMBI_FMT_SID_SN3D: + ch_ord_out = AMBI_CHANNEL_ORDER_SID; + ch_norm_out = AMBI_NORM_SN3D; + break; + case AMBI_FMT_SID_N3D: + ch_ord_out = AMBI_CHANNEL_ORDER_SID; + ch_norm_out = AMBI_NORM_N3D; + break; + default: + assert( 0 && "Unsupported out_format!" ); + } + + if ( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + { + renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + } + + if ( ch_ord_in != ch_ord_out ) + { + reorder_channels( in, out, order, ch_ord_in, ch_ord_out ); + } + + if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + { + renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); } return 0; -- GitLab From d9d83cc59a610533ad037648dafc0d97a9c10724 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 12:38:27 +0200 Subject: [PATCH 049/102] add format AMBI_FMT_FM_FM --- apps/decoder.c | 2 +- apps/encoder.c | 2 +- lib_util/ambi_convert.c | 10 +++++++++- lib_util/ambi_convert.h | 1 + readme.txt | 4 ++-- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 84ec71a32f..30b5d0f265 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1734,7 +1734,7 @@ static void usage_dec( void ) fprintf( stdout, "--------\n" ); #ifdef AMBISONICS_CONVENTIONS fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D)" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D)" ); #endif fprintf( stdout, "-VOIP : VoIP mode: RTP in G192\n" ); fprintf( stdout, "-VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump\n" ); diff --git a/apps/encoder.c b/apps/encoder.c index e063d7a7d7..ec1773d5d2 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1909,7 +1909,7 @@ static void usage_enc( void ) fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); #ifdef AMBISONICS_CONVENTIONS fprintf( stdout, "-sba_convention n : Ambisonics convention of the input signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D)" ); + fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D)" ); #endif fprintf( stdout, "-masa Ch File : MASA format \n" ); fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8af419b9c0..7f70b8d721 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -156,6 +156,10 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT ch_ord_in = AMBI_CHANNEL_ORDER_FM; ch_norm_in = AMBI_NORM_MAXN; break; + case AMBI_FMT_FM_FM: + ch_ord_in = AMBI_CHANNEL_ORDER_FM; + ch_norm_in = AMBI_NORM_FM; + break; case AMBI_FMT_SID_SN3D: ch_ord_in = AMBI_CHANNEL_ORDER_SID; ch_norm_in = AMBI_NORM_SN3D; @@ -180,7 +184,11 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT break; case AMBI_FMT_FM_MAXN: ch_ord_out = AMBI_CHANNEL_ORDER_FM; - ch_norm_in = AMBI_NORM_MAXN; + ch_norm_out = AMBI_NORM_MAXN; + break; + case AMBI_FMT_FM_FM: + ch_ord_out = AMBI_CHANNEL_ORDER_FM; + ch_norm_out = AMBI_NORM_FM; break; case AMBI_FMT_SID_SN3D: ch_ord_out = AMBI_CHANNEL_ORDER_SID; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index d6db18a742..49fdc38838 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -41,6 +41,7 @@ typedef enum AMBI_FMT_ACN_SN3D = 0, AMBI_FMT_ACN_N3D, AMBI_FMT_FM_MAXN, + AMBI_FMT_FM_FM, AMBI_FMT_SID_SN3D, AMBI_FMT_SID_N3D } AMBI_FMT; diff --git a/readme.txt b/readme.txt index 92907bedfd..d360a541e5 100644 --- a/readme.txt +++ b/readme.txt @@ -195,7 +195,7 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, where Order specifies the Ambisionics order (1-3), where positive (+) means full 3D and negative (-) only 2D/planar components to be coded -sba_convention n : Ambisonics convention of the input signal - where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D) + where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D) -masa Ch File : MASA format where Ch specifies the number of MASA input/transport channels (1 or 2): and File specifies input file containing parametric MASA metadata @@ -257,7 +257,7 @@ output_file : Output audio filename Options: -------- -sba_convention n : Ambisonics convention of the output signal - where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (SID-SN3D), 4 (SID-N3D) + : where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D) -VOIP : VoIP mode: RTP in G192 -VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump -VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump -- GitLab From bc335b7601282fea46a11406c06af6b89905bd50 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 15:25:03 +0200 Subject: [PATCH 050/102] add comments to clarify the meaning of the constants in ambi_convert.c --- lib_util/ambi_convert.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 7f70b8d721..de5ba47841 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -37,25 +37,25 @@ #include "ivas_cnst.h" #include "ambi_convert.h" -#define SQRT_2_ 1.4142135f -#define SQRT_3_ 1.7320508f -#define SQRT_5_ 2.2360679f -#define SQRT_7_ 2.64575131f - -#define INV_SQRT_2_ 0.7071067f -#define INV_SQRT_3_ 0.5773502f -#define INV_SQRT_5_ 0.4472135f -#define INV_SQRT_7_ 0.3779644f - -#define TWO_OVER_SQRT_3_ 1.1547005f -#define THREE_OVER_SQRT_5_ 1.3416408f -#define SQRT_8_OVER_5_ 1.2649110f -#define SQRT_45_OVER_32_ 1.1858541f - -#define INV_TWO_OVER_SQRT_3_ 0.8660254f -#define INV_THREE_OVER_SQRT_5_ 0.7453560f -#define INV_SQRT_8_OVER_5_ 0.7905694f -#define INV_SQRT_45_OVER_32_ 0.8432740f +#define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ +#define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ +#define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ +#define SQRT_7_ 2.64575131f /* sqrtf(7.0f) */ + +#define INV_SQRT_2_ 0.7071067f /* 1.0f/sqrtf(2.0f) */ +#define INV_SQRT_3_ 0.5773502f /* 1.0f/sqrtf(3.0f) */ +#define INV_SQRT_5_ 0.4472135f /* 1.0f/sqrtf(5.0f) */ +#define INV_SQRT_7_ 0.3779644f /* 1.0f/sqrtf(7.0f) */ + +#define TWO_OVER_SQRT_3_ 1.1547005f /* 2.0f/sqrtf(3.0f) */ +#define THREE_OVER_SQRT_5_ 1.3416408f /* 3.0f/sqrtf(5.0f) */ +#define SQRT_8_OVER_5_ 1.2649110f /* sqrtf(8.0f/5.0f) */ +#define SQRT_45_OVER_32_ 1.1858541f /* sqrtf(45.0f/32.0f) */ + +#define INV_TWO_OVER_SQRT_3_ 0.8660254f /* 1.0f/TWO_OVER_SQRT_3_ */ +#define INV_THREE_OVER_SQRT_5_ 0.7453560f /* 1.0f/THREE_OVER_SQRT_5_ */ +#define INV_SQRT_8_OVER_5_ 0.7905694f /* 1.0f/INV_SQRT_8_OVER_5_ */ +#define INV_SQRT_45_OVER_32_ 0.8432740f /* 1.0f/SQRT_45_OVER_32_ */ #define AMBI_MAX_CHANNELS 16 -- GitLab From 9216fb470ef298a01beabad20640fe5e690303d7 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 15:25:35 +0200 Subject: [PATCH 051/102] fix formatting --- lib_util/ambi_convert.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index de5ba47841..8bd31cb95f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -37,25 +37,25 @@ #include "ivas_cnst.h" #include "ambi_convert.h" -#define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ -#define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ -#define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ -#define SQRT_7_ 2.64575131f /* sqrtf(7.0f) */ - -#define INV_SQRT_2_ 0.7071067f /* 1.0f/sqrtf(2.0f) */ -#define INV_SQRT_3_ 0.5773502f /* 1.0f/sqrtf(3.0f) */ -#define INV_SQRT_5_ 0.4472135f /* 1.0f/sqrtf(5.0f) */ -#define INV_SQRT_7_ 0.3779644f /* 1.0f/sqrtf(7.0f) */ - -#define TWO_OVER_SQRT_3_ 1.1547005f /* 2.0f/sqrtf(3.0f) */ -#define THREE_OVER_SQRT_5_ 1.3416408f /* 3.0f/sqrtf(5.0f) */ -#define SQRT_8_OVER_5_ 1.2649110f /* sqrtf(8.0f/5.0f) */ -#define SQRT_45_OVER_32_ 1.1858541f /* sqrtf(45.0f/32.0f) */ - -#define INV_TWO_OVER_SQRT_3_ 0.8660254f /* 1.0f/TWO_OVER_SQRT_3_ */ -#define INV_THREE_OVER_SQRT_5_ 0.7453560f /* 1.0f/THREE_OVER_SQRT_5_ */ -#define INV_SQRT_8_OVER_5_ 0.7905694f /* 1.0f/INV_SQRT_8_OVER_5_ */ -#define INV_SQRT_45_OVER_32_ 0.8432740f /* 1.0f/SQRT_45_OVER_32_ */ +#define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ +#define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ +#define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ +#define SQRT_7_ 2.64575131f /* sqrtf(7.0f) */ + +#define INV_SQRT_2_ 0.7071067f /* 1.0f/sqrtf(2.0f) */ +#define INV_SQRT_3_ 0.5773502f /* 1.0f/sqrtf(3.0f) */ +#define INV_SQRT_5_ 0.4472135f /* 1.0f/sqrtf(5.0f) */ +#define INV_SQRT_7_ 0.3779644f /* 1.0f/sqrtf(7.0f) */ + +#define TWO_OVER_SQRT_3_ 1.1547005f /* 2.0f/sqrtf(3.0f) */ +#define THREE_OVER_SQRT_5_ 1.3416408f /* 3.0f/sqrtf(5.0f) */ +#define SQRT_8_OVER_5_ 1.2649110f /* sqrtf(8.0f/5.0f) */ +#define SQRT_45_OVER_32_ 1.1858541f /* sqrtf(45.0f/32.0f) */ + +#define INV_TWO_OVER_SQRT_3_ 0.8660254f /* 1.0f/TWO_OVER_SQRT_3_ */ +#define INV_THREE_OVER_SQRT_5_ 0.7453560f /* 1.0f/THREE_OVER_SQRT_5_ */ +#define INV_SQRT_8_OVER_5_ 0.7905694f /* 1.0f/INV_SQRT_8_OVER_5_ */ +#define INV_SQRT_45_OVER_32_ 0.8432740f /* 1.0f/SQRT_45_OVER_32_ */ #define AMBI_MAX_CHANNELS 16 -- GitLab From 356897de0595fcb6b88e98d760fb72442ddf3a0a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 15:27:28 +0200 Subject: [PATCH 052/102] store the constant SQRT_7_ with 7 digits precision --- lib_util/ambi_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8bd31cb95f..5cfa1832e5 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -40,7 +40,7 @@ #define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ #define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ #define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ -#define SQRT_7_ 2.64575131f /* sqrtf(7.0f) */ +#define SQRT_7_ 2.6457513f /* sqrtf(7.0f) */ #define INV_SQRT_2_ 0.7071067f /* 1.0f/sqrtf(2.0f) */ #define INV_SQRT_3_ 0.5773502f /* 1.0f/sqrtf(3.0f) */ -- GitLab From 260155369f00dc29b86f06620c49a9753513e7c7 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 13 Jun 2024 15:33:58 +0200 Subject: [PATCH 053/102] fix formatting --- lib_util/ambi_convert.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 5cfa1832e5..ba12b8ec1e 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -37,10 +37,10 @@ #include "ivas_cnst.h" #include "ambi_convert.h" -#define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ -#define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ -#define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ -#define SQRT_7_ 2.6457513f /* sqrtf(7.0f) */ +#define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ +#define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ +#define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ +#define SQRT_7_ 2.6457513f /* sqrtf(7.0f) */ #define INV_SQRT_2_ 0.7071067f /* 1.0f/sqrtf(2.0f) */ #define INV_SQRT_3_ 0.5773502f /* 1.0f/sqrtf(3.0f) */ -- GitLab From 0ef5c4cd8b358330aa9c12b098d2ce89f7315621 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 12:49:14 +0200 Subject: [PATCH 054/102] add test vectors in different ambisonics conventions --- scripts/testv/stv3OA48c_FuMa.wav | 3 +++ scripts/testv/stv3OA48c_N3D.wav | 3 +++ scripts/testv/stv3OA48c_SN3D-SID.wav | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 scripts/testv/stv3OA48c_FuMa.wav create mode 100644 scripts/testv/stv3OA48c_N3D.wav create mode 100644 scripts/testv/stv3OA48c_SN3D-SID.wav diff --git a/scripts/testv/stv3OA48c_FuMa.wav b/scripts/testv/stv3OA48c_FuMa.wav new file mode 100644 index 0000000000..6b52c739ce --- /dev/null +++ b/scripts/testv/stv3OA48c_FuMa.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95f21ed4f2134ff6a43e2f3a1654396e1c02bc5e78f3ddd69071adb16567cb53 +size 30720844 diff --git a/scripts/testv/stv3OA48c_N3D.wav b/scripts/testv/stv3OA48c_N3D.wav new file mode 100644 index 0000000000..150b8a91d9 --- /dev/null +++ b/scripts/testv/stv3OA48c_N3D.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68c29e8be1afe7cac05914a6152438f86a417b30e88241eb25b061de14a98b73 +size 30720844 diff --git a/scripts/testv/stv3OA48c_SN3D-SID.wav b/scripts/testv/stv3OA48c_SN3D-SID.wav new file mode 100644 index 0000000000..6e46a91732 --- /dev/null +++ b/scripts/testv/stv3OA48c_SN3D-SID.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:363204e18b68f242fd97d76fbd0a911d9b8a479ecf9b68ffaa47114ddc2ab9af +size 30720844 -- GitLab From 86103456f5c158a6f25536757f5467e454d6a527 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 13:09:37 +0200 Subject: [PATCH 055/102] add test cases with SBA input and output conversions --- scripts/config/self_test.prm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index 3a071276cb..474d501e27 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -750,6 +750,18 @@ eid-xor -fer -vbr -bs g192 -ep g192 bit ../scripts/dly_error_profiles/ep_5pct.g1 ../IVAS_cod -sba 1 96000 48 testv/stvFOA48c.wav bit ../IVAS_dec FOA 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_FOA.tst +// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, ACN-N3D input +../IVAS_cod -sba 3 -sba_convention 1 96000 48 testv/stvHOA48c_N3D.wav bit +../IVAS_dec -sba_convention 3 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_ACN-N3D_FM-FM.tst + +// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, FM input +../IVAS_cod -sba 3 -sba_convention 3 96000 48 testv/stvHOA48c_FuMa.wav bit +../IVAS_dec -sba_convention 5 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_FM-FM_SID-SN3D.tst + +// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, SN3D-SID input +../IVAS_cod -sba 5 -sba_convention 3 96000 48 testv/stvHOA48c_SN3D-SID.wav bit +../IVAS_dec -sba_convention 0 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_SN3D-SID_ACN-SN3D.tst + // SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM IR out, HR ../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit ../IVAS_dec -t testv/headrot_case00_3000_q.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot.tst -- GitLab From eb4ee2b3368a5578eac3d20a60be5267a5fd8ed6 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 13:47:38 +0200 Subject: [PATCH 056/102] fix typo in scripts/config/self_test.prm --- scripts/config/self_test.prm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index 474d501e27..51911eda41 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -759,7 +759,7 @@ eid-xor -fer -vbr -bs g192 -ep g192 bit ../scripts/dly_error_profiles/ep_5pct.g1 ../IVAS_dec -sba_convention 5 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_FM-FM_SID-SN3D.tst // SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, SN3D-SID input -../IVAS_cod -sba 5 -sba_convention 3 96000 48 testv/stvHOA48c_SN3D-SID.wav bit +../IVAS_cod -sba 3 -sba_convention 5 96000 48 testv/stvHOA48c_SN3D-SID.wav bit ../IVAS_dec -sba_convention 0 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_SN3D-SID_ACN-SN3D.tst // SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM IR out, HR -- GitLab From dffd6aa0fdd39e3fce46b7c65bfd776b0877cef9 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 13:50:36 +0200 Subject: [PATCH 057/102] fix argument check in encoder and decoder command line parser --- apps/decoder.c | 6 +++--- apps/encoder.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 30b5d0f265..85b0413315 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1280,14 +1280,14 @@ static bool parseCmdlIVAS_dec( else { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number [0-4]!\n\n" ); + fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number [0-5]!\n\n" ); usage_dec(); return false; } - if ( tmp < 0 || tmp > 4 ) + if ( tmp < 0 || tmp > 5 ) { tmp = -1; - fprintf( stderr, "Error: SBA output convention must be specified, expecting a number in [0,4]!\n\n" ); + fprintf( stderr, "Error: SBA output convention must be specified, expecting a number in [0,5]!\n\n" ); usage_dec(); return false; } diff --git a/apps/encoder.c b/apps/encoder.c index ec1773d5d2..521298262e 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -1219,14 +1219,14 @@ static bool parseCmdlIVAS_enc( else { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,5]!\n\n" ); usage_enc(); return false; } - if ( tmp < 0 || tmp > 4 ) + if ( tmp < 0 || tmp > 5 ) { tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,4]!\n\n" ); + fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,5]!\n\n" ); usage_enc(); return false; } -- GitLab From 6d7399875414d7254667418caf4cdccb355f8c62 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 13:58:33 +0200 Subject: [PATCH 058/102] rename scaling-factors variables --- lib_util/ambi_convert.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index ba12b8ec1e..bcb997a2ca 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -74,7 +74,7 @@ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; -static const float N3D_SCALING_FACTOR = 1.0f; +static const float N3D_SN3D_SCALING_FACTOR = 1.0f; static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, @@ -87,7 +87,7 @@ static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float MAXN_SCALING_FACTOR = 1.0f; +static const float MAXN_SN3D_SCALING_FACTOR = 1.0f; static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, @@ -100,7 +100,7 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float FM_SCALING_FACTOR = INV_SQRT_2; +static const float FM_SN3D_SCALING_FACTOR = INV_SQRT_2; /* ---------------------------- @@ -234,17 +234,17 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; - sf = 1.f / N3D_SCALING_FACTOR; + sf = 1.f / N3D_SN3D_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; - sf = 1.f / MAXN_SCALING_FACTOR; + sf = 1.f / MAXN_SN3D_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; - sf = 1.f / FM_SCALING_FACTOR; + sf = 1.f / FM_SN3D_SCALING_FACTOR; } else { @@ -256,17 +256,17 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; - sf = N3D_SCALING_FACTOR; - } + sf = N3D_SN3D_SCALING_FACTOR; + } else if ( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; - sf = MAXN_SCALING_FACTOR; + sf = MAXN_SN3D_SCALING_FACTOR; } else if ( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; - sf = FM_SCALING_FACTOR; + sf = FM_SN3D_SCALING_FACTOR; } else { -- GitLab From a0dad85404efe1b6e1b0ec287c7a2f980f1355a8 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 14 Jun 2024 14:20:15 +0200 Subject: [PATCH 059/102] fix formatting --- lib_util/ambi_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index bcb997a2ca..aaaff3ed55 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -257,7 +257,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA { conversion_table = N3D_SN3D; sf = N3D_SN3D_SCALING_FACTOR; - } + } else if ( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; -- GitLab From 2da1bb0cc52ed3210c9c7c4f8539048fa2ae536c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 17 Jun 2024 08:54:11 +0200 Subject: [PATCH 060/102] temporarily delete the new test cases to fix pipeline --- scripts/config/self_test.prm | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index 51911eda41..3a071276cb 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -750,18 +750,6 @@ eid-xor -fer -vbr -bs g192 -ep g192 bit ../scripts/dly_error_profiles/ep_5pct.g1 ../IVAS_cod -sba 1 96000 48 testv/stvFOA48c.wav bit ../IVAS_dec FOA 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_FOA.tst -// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, ACN-N3D input -../IVAS_cod -sba 3 -sba_convention 1 96000 48 testv/stvHOA48c_N3D.wav bit -../IVAS_dec -sba_convention 3 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_ACN-N3D_FM-FM.tst - -// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, FM input -../IVAS_cod -sba 3 -sba_convention 3 96000 48 testv/stvHOA48c_FuMa.wav bit -../IVAS_dec -sba_convention 5 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_FM-FM_SID-SN3D.tst - -// SBA at 96 kbps, 48kHz in, 48kHz out, HOA out, SN3D-SID input -../IVAS_cod -sba 3 -sba_convention 5 96000 48 testv/stvHOA48c_SN3D-SID.wav bit -../IVAS_dec -sba_convention 0 HOA3 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_HOA_SN3D-SID_ACN-SN3D.tst - // SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM IR out, HR ../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit ../IVAS_dec -t testv/headrot_case00_3000_q.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot.tst -- GitLab From fc159995a2fa0b3da36893f602890939e6fae370 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 17 Jun 2024 12:29:17 +0200 Subject: [PATCH 061/102] never amplify any channel with any conversion --- lib_util/ambi_convert.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index aaaff3ed55..d31704063f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -75,6 +75,7 @@ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; static const float N3D_SN3D_SCALING_FACTOR = 1.0f; +static const float SN3D_N3D_SCALING_FACTOR = INV_SQRT_7_; static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, @@ -88,6 +89,8 @@ static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; static const float MAXN_SN3D_SCALING_FACTOR = 1.0f; +static const float SN3D_MAXN_SCALING_FACTOR = INV_THREE_OVER_SQRT_5_; + static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, @@ -101,6 +104,7 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; static const float FM_SN3D_SCALING_FACTOR = INV_SQRT_2; +static const float SN3D_FM_SCALING_FACTOR = INV_THREE_OVER_SQRT_5_; /* ---------------------------- @@ -234,17 +238,17 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; - sf = 1.f / N3D_SN3D_SCALING_FACTOR; + sf = SN3D_N3D_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; - sf = 1.f / MAXN_SN3D_SCALING_FACTOR; + sf = SN3D_MAXN_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; - sf = 1.f / FM_SN3D_SCALING_FACTOR; + sf = SN3D_FM_SCALING_FACTOR; } else { -- GitLab From 2e77d3d9c061b18338c71584e8950c322aed7f15 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 17 Jun 2024 12:36:59 +0200 Subject: [PATCH 062/102] fix formatting --- lib_util/ambi_convert.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index d31704063f..76939aa659 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -92,7 +92,6 @@ static const float MAXN_SN3D_SCALING_FACTOR = 1.0f; static const float SN3D_MAXN_SCALING_FACTOR = INV_THREE_OVER_SQRT_5_; - static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, -- GitLab From d5db6eb00aaade7f2c8611d1f2bd5f7fe700eb28 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:33:10 +0200 Subject: [PATCH 063/102] revert changes to VS project files --- Workspace_msvc/decoder.vcxproj | 2 +- Workspace_msvc/lib_com.vcxproj | 4 ++-- Workspace_msvc/lib_dec.vcxproj | 4 ++-- Workspace_msvc/lib_enc.vcxproj | 4 ++-- Workspace_msvc/lib_isar.vcxproj | 4 ++-- Workspace_msvc/lib_rend.vcxproj | 4 ++-- Workspace_msvc/lib_util.vcxproj | 4 +--- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Workspace_msvc/decoder.vcxproj b/Workspace_msvc/decoder.vcxproj index 00e29933a4..c124382c9c 100644 --- a/Workspace_msvc/decoder.vcxproj +++ b/Workspace_msvc/decoder.vcxproj @@ -173,4 +173,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index 9706441d6d..223f837a2e 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -59,7 +59,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_util;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -311,4 +311,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 4f4803ac82..3c7ea3e597 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -348,4 +348,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 91a19db89b..ba0c4c9b6f 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_util;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -364,4 +364,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_isar.vcxproj b/Workspace_msvc/lib_isar.vcxproj index 2f089e3002..fceeb731ce 100644 --- a/Workspace_msvc/lib_isar.vcxproj +++ b/Workspace_msvc/lib_isar.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_util;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_rend;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -197,4 +197,4 @@ - \ No newline at end of file + diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index fcb56e1d21..27d4a19a69 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -68,7 +68,7 @@ Disabled - ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_util;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_com;..\lib_debug;..\lib_dec;..\lib_enc;..\lib_isar;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);WIN32;%(PreprocessorDefinitions) EnableFastChecks @@ -209,4 +209,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 37dc0515c5..79e5545f3f 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -100,7 +100,6 @@ - @@ -128,7 +127,6 @@ - @@ -165,4 +163,4 @@ - + \ No newline at end of file -- GitLab From 52dfffedfeb6871d7a2fb54b778be567973acf54 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:35:26 +0200 Subject: [PATCH 064/102] remove sba_convention argument from encoder.c and decoder.c --- apps/decoder.c | 245 +++++++++++++++++++++++++++++++++++++------------ apps/encoder.c | 57 +----------- 2 files changed, 187 insertions(+), 115 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 85b0413315..2cd7608cbc 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -43,11 +43,10 @@ #include "masa_file_writer.h" #include "render_config_reader.h" #include "rotation_file_reader.h" -#ifdef AMBISONICS_CONVENTIONS -#include "ambi_convert.h" -#endif #include "aeid_file_reader.h" +#ifdef SPLIT_REND_WITH_HEAD_ROT #include "split_render_file_read_write.h" +#endif #ifdef VARIABLE_SPEED_DECODING #include "tsm_scale_file_reader.h" #include @@ -135,7 +134,9 @@ typedef struct float non_diegetic_pan_gain; bool renderConfigEnabled; char *renderConfigFilename; +#ifdef SPLIT_REND_WITH_HEAD_ROT char *outputMdFilename; +#endif IVAS_DEC_COMPLEXITY_LEVEL complexityLevel; bool tsmEnabled; IVAS_RENDER_FRAMESIZE renderFramesize; @@ -153,9 +154,6 @@ typedef struct AcousticEnvironmentSequence aeSequence; int16_t Opt_dpid_on; uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS]; -#ifdef AMBISONICS_CONVENTIONS - AMBI_FMT sba_output_fmt; -#endif } DecArguments; @@ -166,7 +164,11 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); +#ifdef SPLIT_REND_WITH_HEAD_ROT static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#else +static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#endif static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #ifdef DEBUGGING @@ -188,8 +190,10 @@ int main( bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ DecArguments arg; ivas_error error = IVAS_ERR_UNKNOWN; +#ifdef SPLIT_REND_WITH_HEAD_ROT ISAR_SPLIT_REND_BITS_DATA splitRendBits; uint8_t splitRendBitsBuf[ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES]; +#endif /* Any handles that require cleanup must be declared here and initialized to NULL */ IVAS_DEC_HANDLE hIvasDec = NULL; @@ -222,7 +226,9 @@ int main( reset_mem( USE_BYTES ); #endif +#ifdef SPLIT_REND_WITH_HEAD_ROT splitRendBits.bits_buf = splitRendBitsBuf; +#endif /*------------------------------------------------------------------------------------------* * Parse command-line arguments @@ -270,6 +276,7 @@ int main( } } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { fprintf( stdout, "Output metadata file: %s\n", arg.outputWavFilename ); @@ -280,6 +287,7 @@ int main( fprintf( stdout, "Output metadata file: %s\n", arg.outputMdFilename ); } else +#endif { fprintf( stdout, "Output synthesis file: %s\n", arg.outputWavFilename ); } @@ -313,7 +321,11 @@ int main( if ( arg.enableHeadRotation ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB +#ifdef SPLIT_REND_WITH_HEAD_ROT + && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM +#endif + ) { fprintf( stderr, "\nError: Head-rotation file file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -413,8 +425,12 @@ int main( if ( arg.renderConfigEnabled ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && - arg.Opt_non_diegetic_pan == 0 ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB +#ifdef SPLIT_REND_WITH_HEAD_ROT + && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && + arg.Opt_non_diegetic_pan == 0 +#endif + ) { fprintf( stderr, "\nError: Renderer configuration file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -434,13 +450,7 @@ int main( asked_frame_size = arg.renderFramesize; uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : 65535; if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, - arg.Opt_dpid_on, aeID, arg.delayCompensationEnabled -#ifdef AMBISONICS_CONVENTIONS - , - arg.sba_output_fmt -#endif - ) ) != IVAS_ERR_OK ) - + arg.Opt_dpid_on, aeID, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -456,6 +466,7 @@ int main( fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for decoding to EXT!\n" ); } +#ifdef SPLIT_REND_WITH_HEAD_ROT /*------------------------------------------------------------------------------------------* * Configure Split rendering *------------------------------------------------------------------------------------------*/ @@ -477,6 +488,7 @@ int main( arg.enableHeadRotation = true; } +#endif /*------------------------------------------------------------------------------------------* * Configure VoIP mode @@ -605,6 +617,7 @@ int main( IVAS_RENDER_CONFIG_DATA renderConfig; /* sanity check */ +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && arg.Opt_non_diegetic_pan == 0 ) @@ -612,6 +625,13 @@ int main( fprintf( stderr, "\nExternal Renderer Config is supported only when binaural output configurations is used as output OR when Split rendering mode is enabled. Exiting. \n" ); goto cleanup; } +#else + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + fprintf( stderr, "\nExternal Renderer Config is supported only for binaural output configurations. Exiting. \n\n" ); + goto cleanup; + } +#endif if ( ( error = IVAS_DEC_GetRenderConfig( hIvasDec, &renderConfig ) ) != IVAS_ERR_OK ) { @@ -635,6 +655,7 @@ int main( fprintf( stderr, "Failed to get Distance Attenuation \n\n" ); goto cleanup; } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { if ( asked_frame_size != IVAS_RENDER_FRAMESIZE_20MS && @@ -658,6 +679,7 @@ int main( fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for non-0dof split rendering!\n" ); } } +#endif if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { @@ -677,9 +699,13 @@ int main( renderConfig.roomAcoustics.override = true; } +#ifdef SPLIT_REND_WITH_HEAD_ROT +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS /* ISAR frame size is set from command line, not renderer config file. * This will be ignored if output format is not split rendering. */ renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) arg.renderFramesize /* given in number of 5ms subframes */ * 5; +#endif +#endif if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, renderConfig ) ) != IVAS_ERR_OK ) { @@ -837,7 +863,11 @@ int main( } else { +#ifdef SPLIT_REND_WITH_HEAD_ROT error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); +#else + error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf ); +#endif } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -997,6 +1027,7 @@ static IVAS_AUDIO_CONFIG cmdline2config( { output_config = IVAS_AUDIO_CONFIG_BINAURAL; } +#ifdef SPLIT_REND_WITH_HEAD_ROT else if ( strcmp( argv_to_upper, "BINAURAL_SPLIT_CODED" ) == 0 ) { output_config = IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED; @@ -1005,6 +1036,7 @@ static IVAS_AUDIO_CONFIG cmdline2config( { output_config = IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM; } +#endif else if ( strcmp( argv_to_upper, "BINAURAL_ROOM_IR" ) == 0 ) { output_config = IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR; @@ -1080,11 +1112,9 @@ static bool parseCmdlIVAS_dec( arg->renderConfigFilename = NULL; arg->Opt_dpid_on = 0; -#ifdef AMBISONICS_CONVENTIONS - arg->sba_output_fmt = AMBI_FMT_ACN_SN3D; -#endif - +#ifdef SPLIT_REND_WITH_HEAD_ROT arg->outputMdFilename = NULL; +#endif arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192; arg->Opt_non_diegetic_pan = 0; @@ -1265,35 +1295,7 @@ static bool parseCmdlIVAS_dec( } #endif #endif /* #ifdef DEBUGGING */ -#ifdef AMBISONICS_CONVENTIONS - else if ( strcmp( argv_to_upper, "-SBA_CONVENTION" ) == 0 ) - { - int16_t tmp; - i++; - arg->sba_output_fmt = AMBI_FMT_ACN_SN3D; - /* SBA configuration */ - if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%hd", &tmp ) > 0 ) - { - i++; - } - else - { - tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA ouput convention must be specified, expecting a number [0-5]!\n\n" ); - usage_dec(); - return false; - } - if ( tmp < 0 || tmp > 5 ) - { - tmp = -1; - fprintf( stderr, "Error: SBA output convention must be specified, expecting a number in [0,5]!\n\n" ); - usage_dec(); - return false; - } - arg->sba_output_fmt = tmp; - } -#endif else if ( strcmp( argv_to_upper, "-MIME" ) == 0 ) { arg->inputFormat = IVAS_DEC_INPUT_FORMAT_MIME; @@ -1440,6 +1442,7 @@ static bool parseCmdlIVAS_dec( } i += 2; } +#ifdef SPLIT_REND_WITH_HEAD_ROT else if ( strcmp( argv_to_upper, "-OM" ) == 0 ) { arg->outputMdFilename = argv[i + 1]; @@ -1451,6 +1454,7 @@ static bool parseCmdlIVAS_dec( } i += 2; } +#endif else if ( strcmp( argv_to_upper, "-NON_DIEGETIC_PAN" ) == 0 ) { i++; @@ -1720,8 +1724,13 @@ static void usage_dec( void ) fprintf( stdout, "Mandatory parameters:\n" ); fprintf( stdout, "---------------------\n" ); +#ifdef SPLIT_REND_WITH_HEAD_ROT fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, EXT\n" ); +#else + fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); + fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, EXT\n" ); +#endif fprintf( stdout, " By default, channel order and loudspeaker positions are equal to the\n" ); fprintf( stdout, " encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker\n" ); fprintf( stdout, " layout file. See readme.txt for details.\n" ); @@ -1732,10 +1741,6 @@ static void usage_dec( void ) fprintf( stdout, "Options:\n" ); fprintf( stdout, "--------\n" ); -#ifdef AMBISONICS_CONVENTIONS - fprintf( stdout, "-sba_convention n : Ambisonics convention of the output signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D)" ); -#endif fprintf( stdout, "-VOIP : VoIP mode: RTP in G192\n" ); fprintf( stdout, "-VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump\n" ); fprintf( stdout, "-VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump\n" ); @@ -1771,7 +1776,9 @@ static void usage_dec( void ) fprintf( stdout, "-rvf File : Reference vector specified by external trajectory File\n" ); fprintf( stdout, " works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" ); fprintf( stdout, "-render_config File : Renderer configuration File\n" ); +#ifdef SPLIT_REND_WITH_HEAD_ROT fprintf( stdout, "-om File : Metadata output File for BINAURAL_SPLIT_PCM OutputConf (only for Fs = 48 kHz)\n" ); +#endif fprintf( stdout, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with paning P, -90<= P <=90,\n" ); fprintf( stdout, " left or l or 90->left, right or r or -90->right, center or c or 0->middle\n" ); #ifdef DEBUGGING @@ -1828,11 +1835,15 @@ static int16_t app_own_random( int16_t *seed ) *---------------------------------------------------------------------*/ static ivas_error initOnFirstGoodFrame( - IVAS_DEC_HANDLE hIvasDec, /* i/o: */ - const DecArguments arg, /* i : */ - const int16_t numInitialBadFrames, /* i : */ - int16_t *numOutSamples, /* i/o: */ - int16_t *vec_pos_len, /* i/o: */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: */ + const DecArguments arg, /* i : */ + const int16_t numInitialBadFrames, /* i : */ +#ifdef SPLIT_REND_WITH_HEAD_ROT + int16_t *numOutSamples, /* i/o: */ + int16_t *vec_pos_len, /* i/o: */ +#else + const uint16_t numOutSamples, /* i : */ +#endif int16_t *pFullDelayNumSamples, /* o : */ int16_t *pRemainingDelayNumSamples, /* o : */ int32_t *delayTimeScale, /* o : */ @@ -1841,10 +1852,17 @@ static ivas_error initOnFirstGoodFrame( MasaFileWriter **ppMasaWriter, /* o : */ IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : */ int16_t *pNumOutChannels, /* o : */ - uint16_t *pNumObj, /* o : */ - SplitFileReadWrite **splitRendWriter ) +#ifdef SPLIT_REND_WITH_HEAD_ROT + uint16_t *pNumObj, /* o : */ + SplitFileReadWrite **splitRendWriter +#else + uint16_t *pNumObj /* o : */ +#endif +) { +#ifdef SPLIT_REND_WITH_HEAD_ROT int16_t isSplitRend, isSplitCoded; +#endif ivas_error error = IVAS_ERR_UNKNOWN; /* Now delay, number of output channels and frame size are known */ @@ -1854,6 +1872,7 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_is_split_rendering_enabled( hIvasDec, &isSplitRend ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_enabled, code: %d\n", error ); @@ -1870,6 +1889,7 @@ static ivas_error initOnFirstGoodFrame( { pFullDelayNumSamples[0] = 0; } +#endif if ( !arg.delayCompensationEnabled ) { @@ -1891,6 +1911,7 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { /* Open split rendering metadata writer */ @@ -1899,8 +1920,10 @@ static ivas_error initOnFirstGoodFrame( ISAR_SPLIT_REND_CODEC splitRendCodec; int16_t splitRendCodecFrameSizeMs; ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrection; +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS int16_t splitRendIsarFrameSizeMs; int16_t lc3plusHighRes; +#endif if ( ( error = IVAS_DEC_GetDelay( hIvasDec, delayNumSamples_temp, &delayTimeScale_temp ) ) != IVAS_ERR_OK ) { @@ -1908,7 +1931,11 @@ static ivas_error initOnFirstGoodFrame( return error; } +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = IVAS_DEC_GetSplitRendBitstreamHeader( hIvasDec, &splitRendCodec, &poseCorrection, &splitRendIsarFrameSizeMs, &splitRendCodecFrameSizeMs, &lc3plusHighRes ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_GetSplitRendBitstreamHeader( hIvasDec, &splitRendCodec, &poseCorrection, &splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nUnable to get split renderer bitstream header: %s\n", ivas_error_to_string( error ) ); return error; @@ -1916,7 +1943,11 @@ static ivas_error initOnFirstGoodFrame( if ( isSplitCoded ) { +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs, splitRendIsarFrameSizeMs, arg.output_Fs, lc3plusHighRes ) ) != IVAS_ERR_OK ) +#else + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1930,7 +1961,11 @@ static ivas_error initOnFirstGoodFrame( return IVAS_ERR_INVALID_SPLIT_REND_CONFIG; } +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs, splitRendIsarFrameSizeMs, arg.output_Fs, lc3plusHighRes ) ) != IVAS_ERR_OK ) +#else + if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1940,19 +1975,23 @@ static ivas_error initOnFirstGoodFrame( if ( !isSplitCoded ) { +#endif /* Open audio writer and write all previously skipped bad frames now that frame size is known */ if ( ( error = AudioFileWriter_open( ppAfWriter, arg.outputWavFilename, arg.output_Fs, *pNumOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename ); return error; } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *splitRendWriter != NULL ) { ISAR_SPLIT_REND_BITS_DATA splitRendBitsZero; @@ -1962,8 +2001,12 @@ static ivas_error initOnFirstGoodFrame( splitRendBitsZero.buf_len = 0; splitRendBitsZero.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; splitRendBitsZero.pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; +#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS splitRendBitsZero.codec_frame_size_ms = 0; splitRendBitsZero.isar_frame_size_ms = 20; +#else + splitRendBitsZero.codec_frame_size_ms = 20; +#endif if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written ) != IVAS_ERR_OK ) { @@ -1973,10 +2016,19 @@ static ivas_error initOnFirstGoodFrame( } else { +#endif +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *pRemainingDelayNumSamples < *numOutSamples ) +#else + if ( *pRemainingDelayNumSamples < numOutSamples ) +#endif { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) +#else + if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nOutput audio file writer error\n" ); return error; @@ -1985,9 +2037,15 @@ static ivas_error initOnFirstGoodFrame( } else { +#ifdef SPLIT_REND_WITH_HEAD_ROT *pRemainingDelayNumSamples -= *numOutSamples; +#else + *pRemainingDelayNumSamples -= numOutSamples; +#endif } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif } free( zeroBuf ); @@ -2074,6 +2132,7 @@ static ivas_error initOnFirstGoodFrame( } } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *splitRendWriter != NULL ) { if ( numOutSamples == NULL || vec_pos_len == NULL ) @@ -2093,6 +2152,7 @@ static ivas_error initOnFirstGoodFrame( return error; } } +#endif return IVAS_ERR_OK; } @@ -2111,7 +2171,9 @@ static ivas_error decodeG192( RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, +#ifdef SPLIT_REND_WITH_HEAD_ROT ISAR_SPLIT_REND_BITS_DATA *splitRendBits, +#endif IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ) @@ -2147,6 +2209,7 @@ static ivas_error decodeG192( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; +#ifdef SPLIT_REND_WITH_HEAD_ROT SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; @@ -2161,6 +2224,7 @@ static ivas_error decodeG192( fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_coded_out, code: %d\n", error ); return error; } +#endif IVAS_RENDER_CONFIG_DATA renderConfig; RenderConfigReader *renderConfigReader = NULL; @@ -2319,6 +2383,7 @@ static ivas_error decodeG192( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -2334,6 +2399,7 @@ static ivas_error decodeG192( } else { +#endif for ( i = 0; i < num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) @@ -2342,11 +2408,17 @@ static ivas_error decodeG192( goto cleanup; } } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif for ( i = 0; i < num_subframes; i++ ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2470,6 +2542,7 @@ static ivas_error decodeG192( } } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBits, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) @@ -2483,14 +2556,21 @@ static ivas_error decodeG192( } else { +#endif +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif if ( needNewFrame ) { frame++; @@ -2524,7 +2604,11 @@ static ivas_error decodeG192( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) +#else + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) +#endif { goto cleanup; } @@ -2538,6 +2622,7 @@ static ivas_error decodeG192( /* Write current frame */ if ( decodedGoodFrame ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) @@ -2549,6 +2634,7 @@ static ivas_error decodeG192( if ( !isSplitCoded ) { +#endif if ( delayNumSamples < nOutSamples ) { if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) @@ -2562,7 +2648,9 @@ static ivas_error decodeG192( { delayNumSamples -= nOutSamples; } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif } /* Write ISm metadata to external file(s) */ @@ -2683,7 +2771,11 @@ static ivas_error decodeG192( goto cleanup; } +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0 ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2691,7 +2783,11 @@ static ivas_error decodeG192( } /* decode and get samples */ +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2810,14 +2906,18 @@ static ivas_error decodeG192( memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( afWriter != NULL ) { +#endif if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); goto cleanup; } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif /*------------------------------------------------------------------------------------------* * Close files and deallocate resources @@ -2828,7 +2928,9 @@ static ivas_error decodeG192( cleanup: RenderConfigReader_close( &renderConfigReader ); +#ifdef SPLIT_REND_WITH_HEAD_ROT split_rend_reader_writer_close( &splitRendWriter ); +#endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); #ifdef DEBUGGING @@ -3180,6 +3282,7 @@ static ivas_error decodeVoIP( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -3195,6 +3298,7 @@ static ivas_error decodeVoIP( } else { +#endif for ( i = 0; i < num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) @@ -3204,11 +3308,17 @@ static ivas_error decodeVoIP( goto cleanup; } } +#ifdef SPLIT_REND_WITH_HEAD_ROT } +#endif for ( i = 0; i < num_subframes; i++ ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3295,10 +3405,18 @@ static ivas_error decodeVoIP( /* decode and get samples */ +#ifdef SPLIT_REND_WITH_HEAD_ROT #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) +#endif +#else +#ifdef SUPPORT_JBM_TRACEFILE + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) +#endif #endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -3335,10 +3453,15 @@ static ivas_error decodeVoIP( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { +#ifdef SPLIT_REND_WITH_HEAD_ROT SplitFileReadWrite *splitRendWriter = NULL; if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) +#else + if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, + &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) +#endif { goto cleanup; } @@ -3443,7 +3566,11 @@ static ivas_error decodeVoIP( int16_t nSamplesFlushed = 0; /* decode and get samples */ +#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; diff --git a/apps/encoder.c b/apps/encoder.c index 521298262e..b00f4f75fd 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -38,9 +38,6 @@ #include "ism_file_reader.h" #include "jbm_file_reader.h" #include "masa_file_reader.h" -#ifdef AMBISONICS_CONVENTIONS -#include "ambi_convert.h" -#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -124,9 +121,6 @@ typedef struct bool max_bwidth_user; IVAS_ENC_BANDWIDTH maxBandwidth; const char *bandwithProfileFile; -#ifdef AMBISONICS_CONVENTIONS - AMBI_FMT sba_input_fmt; -#endif IVAS_ENC_DTX_CONFIG dtxConfig; int32_t initBitrate; const char *bitrateProfileFile; @@ -414,10 +408,6 @@ int main( #ifdef DEBUG_SBA_AUDIO_DUMP , &numTransportChannels -#endif -#ifdef AMBISONICS_CONVENTIONS - , - arg.sba_input_fmt #endif ) ) != IVAS_ERR_OK ) { @@ -441,12 +431,7 @@ int main( } break; case IVAS_ENC_INPUT_SBA_ISM: - if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca -#ifdef AMBISONICS_CONVENTIONS - , - arg.sba_input_fmt -#endif - ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_ENC_ConfigureForSBAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.sba_ism.numObjects, arg.inputFormatConfig.sba_ism.order, arg.inputFormatConfig.sba_ism.isPlanar, arg.pca ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_ENC_ConfigureForSBAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); exit( -1 ); @@ -894,9 +879,6 @@ static void initArgStruct( EncArguments *arg ) arg->outputBitstreamFilename = NULL; arg->inputFs = 0; arg->inputFormat = IVAS_ENC_INPUT_MONO; -#ifdef AMBISONICS_CONVENTIONS - arg->sba_input_fmt = AMBI_FMT_ACN_SN3D; -#endif arg->is_binaural = false; arg->inputFormatConfig.stereoToMonoDownmix = false; arg->max_bwidth_user = false; @@ -929,7 +911,6 @@ static void initArgStruct( EncArguments *arg ) #endif arg->pca = false; - return; } @@ -1202,38 +1183,6 @@ static bool parseCmdlIVAS_enc( } } - /* ---------------------------------------------------------------- - * SBA input convention - *------------------------------------------------------------------*/ -#ifdef AMBISONICS_CONVENTIONS - else if ( strcmp( argv_to_upper, "-SBA_CONVENTION" ) == 0 ) - { - i++; - arg->sba_input_fmt = AMBI_FMT_ACN_SN3D; - - /* SBA configuration */ - if ( i < argc - 4 && is_number( argv[i] ) && sscanf( argv[i], "%d", &tmp ) > 0 ) - { - i++; - } - else - { - tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,5]!\n\n" ); - usage_enc(); - return false; - } - if ( tmp < 0 || tmp > 5 ) - { - tmp = -1; /* this is to avoid a compilation warning */ - fprintf( stderr, "Error: SBA input convention must be specified, expecting a number in [0,5]!\n\n" ); - usage_enc(); - return false; - } - arg->sba_input_fmt = tmp; - } -#endif - /*-----------------------------------------------------------------* * MIME output file format *-----------------------------------------------------------------*/ @@ -1907,10 +1856,6 @@ static void usage_enc( void ) fprintf( stdout, "-sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D),\n" ); fprintf( stdout, " where Order specifies the Ambisionics order (1-3),\n" ); fprintf( stdout, " where positive (+) means full 3D and negative (-) only 2D/planar components to be coded\n" ); -#ifdef AMBISONICS_CONVENTIONS - fprintf( stdout, "-sba_convention n : Ambisonics convention of the input signal" ); - fprintf( stdout, " where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D)" ); -#endif fprintf( stdout, "-masa Ch File : MASA format \n" ); fprintf( stdout, " where Ch specifies the number of MASA input/transport channels (1 or 2): \n" ); fprintf( stdout, " and File specifies input file containing parametric MASA metadata \n" ); -- GitLab From ab56b0497036f4ffe572bee1191b8ab1d2047339 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:39:19 +0200 Subject: [PATCH 065/102] remove call to the conversion functioins from the codec itself --- lib_com/options.h | 2 -- lib_dec/ivas_sba_dec.c | 12 ------------ lib_dec/ivas_stat_dec.h | 3 --- lib_dec/lib_dec.c | 7 ------- lib_dec/lib_dec.h | 7 ------- lib_enc/ivas_enc.c | 10 ---------- lib_enc/ivas_stat_enc.h | 3 --- lib_enc/lib_enc.c | 15 --------------- lib_enc/lib_enc.h | 11 ----------- 9 files changed, 70 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8833f14762..6a7b5fc981 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -164,8 +164,6 @@ #define FIX_1099_JBM_MD_HANDLE_ALLOC /* VA: issue 1099: Limit the allocation of `hJbmMetadata` handle to MASA and OMASA only */ #define FIX_1111_TDM_LSP_BUFFER /* VA: issue 1111: remove unused buffer `tdm_lspQ_PCh[]' */ -#define AMBISONICS_CONVENTIONS - /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5bc779829b..d13268858c 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -812,18 +812,6 @@ ivas_error ivas_sba_dec_render( } } -#ifdef AMBISONICS_CONVENTIONS - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || - st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) - { - if ( st_ivas->hDecoderConfig->sba_output_fmt != 0 ) - { - convert_ambi_format( output_f, output_f, st_ivas->sba_analysis_order, AMBI_FMT_ACN_SN3D, st_ivas->hDecoderConfig->sba_output_fmt ); - } - } -#endif - if ( st_ivas->hDirAC != NULL && hSpar->slots_rendered == hSpar->num_slots ) { if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 913867183a..2c9b2e99d1 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -988,9 +988,6 @@ typedef struct decoder_config_structure int16_t Opt_Headrotation; /* indicates whether head-rotation is used */ int16_t Opt_RendConfigCustom; /* indicates whether Renderer configuration custom setup is used */ IVAS_HEAD_ORIENT_TRK_T orientation_tracking; /* indicates orientation tracking type */ -#ifdef AMBISONICS_CONVENTIONS - AMBI_FMT sba_output_fmt; -#endif int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ float non_diegetic_pan_gain; /* non diegetic panning gain*/ int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 35d460da39..7ce36f86d6 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -418,10 +418,6 @@ ivas_error IVAS_DEC_Configure( const int16_t Opt_dpid_on, /* i : enable directivity pattern option */ const uint16_t acousticEnvironmentId, /* i : Acoustic environment ID */ const int16_t delayCompensationEnabled /* i : enable delay compensation */ -#ifdef AMBISONICS_CONVENTIONS - , - const AMBI_FMT sba_output_fmt -#endif ) { Decoder_Struct *st_ivas; @@ -462,9 +458,6 @@ ivas_error IVAS_DEC_Configure( st_ivas->element_mode_init = EVS_MONO; hDecoderConfig->nchan_out = 1; } -#ifdef AMBISONICS_CONVENTIONS - hDecoderConfig->sba_output_fmt = sba_output_fmt; -#endif if ( outputConfig != IVAS_AUDIO_CONFIG_EXTERNAL && outputConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index e30b2b5eae..0be389a61d 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -34,9 +34,6 @@ #define LIB_DEC_H #include "common_api_types.h" -#ifdef AMBISONICS_CONVENTIONS -#include "ambi_convert.h" -#endif #include /*---------------------------------------------------------------------* @@ -138,10 +135,6 @@ ivas_error IVAS_DEC_Configure( const int16_t Opt_dpid_on, /* i : enable directivity pattern option */ const uint16_t acousticEnvironmentId, /* i : Acoustic environment ID */ const int16_t delayCompensationEnabled /* i : enable delay compensation */ -#ifdef AMBISONICS_CONVENTIONS - , - const AMBI_FMT sba_output_fmt -#endif ); void IVAS_DEC_Close( diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5869e28a51..4914b59625 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -127,16 +127,6 @@ ivas_error ivas_enc( dbgwrite( data_f[LFE_CHANNEL], sizeof( float ), n_samples_chan, 1, "./res/lfe_input" ); #endif -#ifdef AMBISONICS_CONVENTIONS - if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( hEncoderConfig->sba_input_fmt != 0 ) - { - convert_ambi_format( data_f, data_f, st_ivas->sba_analysis_order, hEncoderConfig->sba_input_fmt, AMBI_FMT_ACN_SN3D ); - } - } -#endif - if ( ivas_format == SBA_FORMAT ) { if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 5118765deb..66656a9273 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1188,9 +1188,6 @@ typedef struct encoder_config_structure int16_t Opt_DTX_ON; /* flag indicating DTX operation */ int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ -#ifdef AMBISONICS_CONVENTIONS - AMBI_FMT sba_input_fmt; -#endif int16_t Opt_RF_ON; /* flag indicating RF (channel-aware) mode */ int16_t rf_fec_offset; /* RF FEC offset */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 84f9fe2421..e54dfdb803 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -492,10 +492,6 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( , int16_t *numTransportChannels #endif -#ifdef AMBISONICS_CONVENTIONS - , - AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ -#endif ) { ENCODER_CONFIG_HANDLE hEncoderConfig; @@ -513,10 +509,6 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->sba_planar = isPlanar; hEncoderConfig->sba_order = order; -#ifdef AMBISONICS_CONVENTIONS - hEncoderConfig->sba_input_fmt = sba_input_fmt; -#endif - /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ @@ -556,10 +548,6 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ const bool Opt_PCA_ON /* i : PCA option flag */ -#ifdef AMBISONICS_CONVENTIONS - , - const int16_t sba_input_fmt -#endif ) { Encoder_Struct *st_ivas; @@ -579,9 +567,6 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ st_ivas->hEncoderConfig->sba_planar = isPlanar; st_ivas->hEncoderConfig->sba_order = order; -#ifdef AMBISONICS_CONVENTIONS - st_ivas->hEncoderConfig->sba_input_fmt = sba_input_fmt; -#endif /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 13177c7cb9..2f40c1ab1b 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -34,9 +34,6 @@ #define LIB_ENC_H #include "common_api_types.h" -#ifdef AMBISONICS_CONVENTIONS -#include "ambi_convert.h" -#endif #include @@ -226,10 +223,6 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */ const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */ const bool Opt_PCA_ON /* i : PCA option flag */ -#ifdef AMBISONICS_CONVENTIONS - , - const int16_t sba_input_fmt -#endif ); /*! r: error code */ @@ -250,10 +243,6 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( , int16_t *numTransportChannels #endif -#ifdef AMBISONICS_CONVENTIONS - , - AMBI_FMT sba_input_fmt /* i : input ambisonics convention */ -#endif ); /*! r: error code */ -- GitLab From b6ecb4c966bca25b04dae584958af3080daa6eb5 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:51:44 +0200 Subject: [PATCH 066/102] remove lib_util from build configs in CMakeLists.txt --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abc646562b..17799f0db0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,20 +131,20 @@ add_library(lib_com ${libComSrcs} ${libComHeaders}) if(UNIX) target_link_libraries(lib_com PRIVATE m) endif() -target_include_directories(lib_com PUBLIC lib_com PRIVATE lib_enc lib_dec lib_rend lib_debug lib_isar lib_util) +target_include_directories(lib_com PUBLIC lib_com PRIVATE lib_enc lib_dec lib_rend lib_debug lib_isar) target_include_directories(lib_com PRIVATE lib_lc3plus) file(GLOB libDebugSrcs "lib_debug/*.c") file(GLOB libDebugHeaders "lib_debug/*.h") add_library(lib_debug ${libDebugSrcs} ${libDebugHeaders}) target_link_libraries(lib_debug lib_com) -target_include_directories(lib_debug PUBLIC lib_debug PRIVATE lib_enc lib_dec lib_rend lib_isar lib_util) +target_include_directories(lib_debug PUBLIC lib_debug PRIVATE lib_enc lib_dec lib_rend lib_isar) file(GLOB libEncSrcs "lib_enc/*.c") file(GLOB libEncHeaders "lib_enc/*.h") add_library(lib_enc ${libEncSrcs} ${libEncHeaders}) target_link_libraries(lib_enc lib_com lib_debug) -target_include_directories(lib_enc PUBLIC lib_enc PRIVATE lib_dec lib_rend lib_isar lib_util) +target_include_directories(lib_enc PUBLIC lib_enc PRIVATE lib_dec lib_rend lib_isar) target_include_directories(lib_enc PRIVATE lib_lc3plus) file(GLOB libLC3plusSrcs "lib_lc3plus/*.c") @@ -156,21 +156,21 @@ file(GLOB libRendSrcs "lib_rend/*.c") file(GLOB libRendHeaders "lib_rend/*.h") add_library(lib_rend ${libRendSrcs} ${libRendHeaders}) -target_link_libraries(lib_rend lib_dec lib_com lib_debug lib_util) # Todo refactor: This dependency on lib_dec should be removed. +target_link_libraries(lib_rend lib_dec lib_com lib_debug) # Todo refactor: This dependency on lib_dec should be removed. target_link_libraries(lib_rend lib_lc3plus lib_isar) -target_include_directories(lib_rend PUBLIC lib_rend PRIVATE lib_enc lib_isar lib_util) +target_include_directories(lib_rend PUBLIC lib_rend PRIVATE lib_enc lib_isar) file(GLOB libDecSrcs "lib_dec/*.c") file(GLOB libDecHeaders "lib_dec/*.h") add_library(lib_dec ${libDecSrcs} ${libDecHeaders}) target_link_libraries(lib_dec lib_com lib_rend lib_debug lib_isar) -target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_enc lib_isar lib_util) +target_include_directories(lib_dec PUBLIC lib_dec lib_rend PRIVATE lib_enc lib_isar) file(GLOB libUtilSrcs "lib_util/*.c") file(GLOB libUtilHeaders "lib_util/*.h") add_library(lib_util ${libUtilSrcs} ${libUtilHeaders}) -target_include_directories(lib_util PUBLIC lib_util PRIVATE lib_com lib_enc lib_dec lib_rend lib_debug lib_util) +target_include_directories(lib_util PUBLIC lib_util PRIVATE lib_com lib_enc lib_dec lib_rend lib_debug) target_include_directories(lib_util PRIVATE lib_lc3plus lib_isar) if(NOT WMOPS) @@ -183,7 +183,7 @@ file(GLOB libISARHeaders "lib_isar/*.h") add_library(lib_isar ${libISARSrcs} ${libISARHeaders}) target_link_libraries(lib_isar lib_com lib_debug lib_lc3plus) # Todo refactor: This dependency on lib_dec should be removed. -target_include_directories(lib_isar PUBLIC lib_isar PRIVATE lib_enc lib_dec lib_rend lib_util) +target_include_directories(lib_isar PUBLIC lib_isar PRIVATE lib_enc lib_dec lib_rend) add_executable(IVAS_cod apps/encoder.c) @@ -200,7 +200,7 @@ endif() add_executable(IVAS_rend apps/renderer.c) target_link_libraries(IVAS_rend lib_rend lib_util lib_isar) -target_include_directories(IVAS_rend PRIVATE lib_enc lib_util) +target_include_directories(IVAS_rend PRIVATE lib_enc) add_executable(ISAR_post_rend apps/isar_post_rend.c) target_link_libraries(ISAR_post_rend lib_isar lib_util) -- GitLab From 8bfbe8ef20feb9afe165701937dc948490e28d9f Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:52:41 +0200 Subject: [PATCH 067/102] remove sb_conversion parameter from readme.txt --- readme.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/readme.txt b/readme.txt index d360a541e5..cd5a01d4be 100644 --- a/readme.txt +++ b/readme.txt @@ -194,8 +194,6 @@ EVS mono is default, for IVAS choose one of the following: -stereo, -ism, -sba, -sba +/-Order : Scene Based Audio input format (Ambisonics ACN/SN3D), where Order specifies the Ambisionics order (1-3), where positive (+) means full 3D and negative (-) only 2D/planar components to be coded --sba_convention n : Ambisonics convention of the input signal - where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D) -masa Ch File : MASA format where Ch specifies the number of MASA input/transport channels (1 or 2): and File specifies input file containing parametric MASA metadata @@ -256,8 +254,6 @@ output_file : Output audio filename Options: -------- --sba_convention n : Ambisonics convention of the output signal - : where n = 0 (ACN-SN3D), 1 (ACN-N3D), 2 (FuMa-MaxN), 3 (FuMa-FuMa), 4 (SID-SN3D), 5 (SID-N3D) -VOIP : VoIP mode: RTP in G192 -VOIP_hf_only=0 : VoIP mode: EVS RTP Payload Format hf_only=0 in rtpdump -VOIP_hf_only=1 : VoIP mode: EVS RTP Payload Format hf_only=1 in rtpdump -- GitLab From f29bc448a4614db8bc6746068fac728d27aa3bdd Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Tue, 18 Jun 2024 16:53:54 +0200 Subject: [PATCH 068/102] remove hint to SBA conventions from README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 836d130196..899e52ddc1 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -please refer to the [Wiki](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/home). For the Ambisonics conventions see [here](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/Ambisonics-conventions). +please refer to the [Wiki](https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/wikis/home) -- GitLab From e62166c6b8d954d18760c34952d1640234bbc07c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 08:30:46 +0200 Subject: [PATCH 069/102] undo experimental changes to lib_enc, lib_dec, and apps --- apps/decoder.c | 195 ++---------------------------------- lib_dec/ivas_spar_decoder.c | 1 - lib_dec/ivas_stat_dec.h | 13 ++- lib_dec/lib_dec.c | 1 - lib_enc/ivas_enc.c | 1 - lib_enc/ivas_stat_enc.h | 2 +- lib_enc/lib_enc.c | 2 +- 7 files changed, 18 insertions(+), 197 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 2cd7608cbc..354d611a95 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -44,9 +44,7 @@ #include "render_config_reader.h" #include "rotation_file_reader.h" #include "aeid_file_reader.h" -#ifdef SPLIT_REND_WITH_HEAD_ROT #include "split_render_file_read_write.h" -#endif #ifdef VARIABLE_SPEED_DECODING #include "tsm_scale_file_reader.h" #include @@ -134,9 +132,7 @@ typedef struct float non_diegetic_pan_gain; bool renderConfigEnabled; char *renderConfigFilename; -#ifdef SPLIT_REND_WITH_HEAD_ROT char *outputMdFilename; -#endif IVAS_DEC_COMPLEXITY_LEVEL complexityLevel; bool tsmEnabled; IVAS_RENDER_FRAMESIZE renderFramesize; @@ -164,11 +160,7 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); -#ifdef SPLIT_REND_WITH_HEAD_ROT static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#else -static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#endif static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #ifdef DEBUGGING @@ -190,10 +182,8 @@ int main( bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */ DecArguments arg; ivas_error error = IVAS_ERR_UNKNOWN; -#ifdef SPLIT_REND_WITH_HEAD_ROT ISAR_SPLIT_REND_BITS_DATA splitRendBits; uint8_t splitRendBitsBuf[ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES]; -#endif /* Any handles that require cleanup must be declared here and initialized to NULL */ IVAS_DEC_HANDLE hIvasDec = NULL; @@ -226,9 +216,7 @@ int main( reset_mem( USE_BYTES ); #endif -#ifdef SPLIT_REND_WITH_HEAD_ROT splitRendBits.bits_buf = splitRendBitsBuf; -#endif /*------------------------------------------------------------------------------------------* * Parse command-line arguments @@ -276,7 +264,6 @@ int main( } } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) { fprintf( stdout, "Output metadata file: %s\n", arg.outputWavFilename ); @@ -287,7 +274,6 @@ int main( fprintf( stdout, "Output metadata file: %s\n", arg.outputMdFilename ); } else -#endif { fprintf( stdout, "Output synthesis file: %s\n", arg.outputWavFilename ); } @@ -321,11 +307,7 @@ int main( if ( arg.enableHeadRotation ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB -#ifdef SPLIT_REND_WITH_HEAD_ROT - && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM -#endif - ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { fprintf( stderr, "\nError: Head-rotation file file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -425,12 +407,8 @@ int main( if ( arg.renderConfigEnabled ) { /* sanity check */ - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB -#ifdef SPLIT_REND_WITH_HEAD_ROT - && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && - arg.Opt_non_diegetic_pan == 0 -#endif - ) + if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && + arg.Opt_non_diegetic_pan == 0 ) { fprintf( stderr, "\nError: Renderer configuration file cannot be used in this output configuration.\n\n" ); goto cleanup; @@ -466,7 +444,6 @@ int main( fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for decoding to EXT!\n" ); } -#ifdef SPLIT_REND_WITH_HEAD_ROT /*------------------------------------------------------------------------------------------* * Configure Split rendering *------------------------------------------------------------------------------------------*/ @@ -488,7 +465,6 @@ int main( arg.enableHeadRotation = true; } -#endif /*------------------------------------------------------------------------------------------* * Configure VoIP mode @@ -617,7 +593,6 @@ int main( IVAS_RENDER_CONFIG_DATA renderConfig; /* sanity check */ -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && arg.Opt_non_diegetic_pan == 0 ) @@ -625,13 +600,6 @@ int main( fprintf( stderr, "\nExternal Renderer Config is supported only when binaural output configurations is used as output OR when Split rendering mode is enabled. Exiting. \n" ); goto cleanup; } -#else - if ( arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && arg.outputConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - fprintf( stderr, "\nExternal Renderer Config is supported only for binaural output configurations. Exiting. \n\n" ); - goto cleanup; - } -#endif if ( ( error = IVAS_DEC_GetRenderConfig( hIvasDec, &renderConfig ) ) != IVAS_ERR_OK ) { @@ -655,7 +623,6 @@ int main( fprintf( stderr, "Failed to get Distance Attenuation \n\n" ); goto cleanup; } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) { if ( asked_frame_size != IVAS_RENDER_FRAMESIZE_20MS && @@ -679,7 +646,6 @@ int main( fprintf( stderr, "\nChanged render framesize, only 20ms are allowed for non-0dof split rendering!\n" ); } } -#endif if ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { @@ -699,13 +665,9 @@ int main( renderConfig.roomAcoustics.override = true; } -#ifdef SPLIT_REND_WITH_HEAD_ROT -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS /* ISAR frame size is set from command line, not renderer config file. * This will be ignored if output format is not split rendering. */ renderConfig.split_rend_config.isar_frame_size_ms = (int16_t) arg.renderFramesize /* given in number of 5ms subframes */ * 5; -#endif -#endif if ( ( error = IVAS_DEC_FeedRenderConfig( hIvasDec, renderConfig ) ) != IVAS_ERR_OK ) { @@ -863,11 +825,7 @@ int main( } else { -#ifdef SPLIT_REND_WITH_HEAD_ROT error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); -#else - error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec, pcmBuf ); -#endif } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -1027,7 +985,6 @@ static IVAS_AUDIO_CONFIG cmdline2config( { output_config = IVAS_AUDIO_CONFIG_BINAURAL; } -#ifdef SPLIT_REND_WITH_HEAD_ROT else if ( strcmp( argv_to_upper, "BINAURAL_SPLIT_CODED" ) == 0 ) { output_config = IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED; @@ -1036,7 +993,6 @@ static IVAS_AUDIO_CONFIG cmdline2config( { output_config = IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM; } -#endif else if ( strcmp( argv_to_upper, "BINAURAL_ROOM_IR" ) == 0 ) { output_config = IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR; @@ -1112,9 +1068,7 @@ static bool parseCmdlIVAS_dec( arg->renderConfigFilename = NULL; arg->Opt_dpid_on = 0; -#ifdef SPLIT_REND_WITH_HEAD_ROT arg->outputMdFilename = NULL; -#endif arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192; arg->Opt_non_diegetic_pan = 0; @@ -1442,7 +1396,6 @@ static bool parseCmdlIVAS_dec( } i += 2; } -#ifdef SPLIT_REND_WITH_HEAD_ROT else if ( strcmp( argv_to_upper, "-OM" ) == 0 ) { arg->outputMdFilename = argv[i + 1]; @@ -1454,7 +1407,6 @@ static bool parseCmdlIVAS_dec( } i += 2; } -#endif else if ( strcmp( argv_to_upper, "-NON_DIEGETIC_PAN" ) == 0 ) { i++; @@ -1724,13 +1676,8 @@ static void usage_dec( void ) fprintf( stdout, "Mandatory parameters:\n" ); fprintf( stdout, "---------------------\n" ); -#ifdef SPLIT_REND_WITH_HEAD_ROT fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, BINAURAL_SPLIT_CODED, BINAURAL_SPLIT_PCM, EXT\n" ); -#else - fprintf( stdout, "OutputConf : Output configuration: MONO, STEREO, 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4, FOA,\n" ); - fprintf( stdout, " HOA2, HOA3, BINAURAL, BINAURAL_ROOM_IR, BINAURAL_ROOM_REVERB, EXT\n" ); -#endif fprintf( stdout, " By default, channel order and loudspeaker positions are equal to the\n" ); fprintf( stdout, " encoder. For loudspeaker outputs, OutputConf can be a custom loudspeaker\n" ); fprintf( stdout, " layout file. See readme.txt for details.\n" ); @@ -1776,9 +1723,7 @@ static void usage_dec( void ) fprintf( stdout, "-rvf File : Reference vector specified by external trajectory File\n" ); fprintf( stdout, " works only in combination with '-otr ref_vec' and 'ref_vec_lev' modes\n" ); fprintf( stdout, "-render_config File : Renderer configuration File\n" ); -#ifdef SPLIT_REND_WITH_HEAD_ROT fprintf( stdout, "-om File : Metadata output File for BINAURAL_SPLIT_PCM OutputConf (only for Fs = 48 kHz)\n" ); -#endif fprintf( stdout, "-non_diegetic_pan P : panning mono non-diegetic sound to stereo with paning P, -90<= P <=90,\n" ); fprintf( stdout, " left or l or 90->left, right or r or -90->right, center or c or 0->middle\n" ); #ifdef DEBUGGING @@ -1835,15 +1780,11 @@ static int16_t app_own_random( int16_t *seed ) *---------------------------------------------------------------------*/ static ivas_error initOnFirstGoodFrame( - IVAS_DEC_HANDLE hIvasDec, /* i/o: */ - const DecArguments arg, /* i : */ - const int16_t numInitialBadFrames, /* i : */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - int16_t *numOutSamples, /* i/o: */ - int16_t *vec_pos_len, /* i/o: */ -#else - const uint16_t numOutSamples, /* i : */ -#endif + IVAS_DEC_HANDLE hIvasDec, /* i/o: */ + const DecArguments arg, /* i : */ + const int16_t numInitialBadFrames, /* i : */ + int16_t *numOutSamples, /* i/o: */ + int16_t *vec_pos_len, /* i/o: */ int16_t *pFullDelayNumSamples, /* o : */ int16_t *pRemainingDelayNumSamples, /* o : */ int32_t *delayTimeScale, /* o : */ @@ -1852,17 +1793,10 @@ static ivas_error initOnFirstGoodFrame( MasaFileWriter **ppMasaWriter, /* o : */ IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS], /* o : */ int16_t *pNumOutChannels, /* o : */ -#ifdef SPLIT_REND_WITH_HEAD_ROT - uint16_t *pNumObj, /* o : */ - SplitFileReadWrite **splitRendWriter -#else - uint16_t *pNumObj /* o : */ -#endif -) + uint16_t *pNumObj, /* o : */ + SplitFileReadWrite **splitRendWriter ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT int16_t isSplitRend, isSplitCoded; -#endif ivas_error error = IVAS_ERR_UNKNOWN; /* Now delay, number of output channels and frame size are known */ @@ -1872,7 +1806,6 @@ static ivas_error initOnFirstGoodFrame( return error; } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_is_split_rendering_enabled( hIvasDec, &isSplitRend ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_enabled, code: %d\n", error ); @@ -1889,7 +1822,6 @@ static ivas_error initOnFirstGoodFrame( { pFullDelayNumSamples[0] = 0; } -#endif if ( !arg.delayCompensationEnabled ) { @@ -1911,7 +1843,6 @@ static ivas_error initOnFirstGoodFrame( return error; } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { /* Open split rendering metadata writer */ @@ -1920,10 +1851,8 @@ static ivas_error initOnFirstGoodFrame( ISAR_SPLIT_REND_CODEC splitRendCodec; int16_t splitRendCodecFrameSizeMs; ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrection; -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS int16_t splitRendIsarFrameSizeMs; int16_t lc3plusHighRes; -#endif if ( ( error = IVAS_DEC_GetDelay( hIvasDec, delayNumSamples_temp, &delayTimeScale_temp ) ) != IVAS_ERR_OK ) { @@ -1931,11 +1860,7 @@ static ivas_error initOnFirstGoodFrame( return error; } -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = IVAS_DEC_GetSplitRendBitstreamHeader( hIvasDec, &splitRendCodec, &poseCorrection, &splitRendIsarFrameSizeMs, &splitRendCodecFrameSizeMs, &lc3plusHighRes ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_GetSplitRendBitstreamHeader( hIvasDec, &splitRendCodec, &poseCorrection, &splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nUnable to get split renderer bitstream header: %s\n", ivas_error_to_string( error ) ); return error; @@ -1943,11 +1868,7 @@ static ivas_error initOnFirstGoodFrame( if ( isSplitCoded ) { -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs, splitRendIsarFrameSizeMs, arg.output_Fs, lc3plusHighRes ) ) != IVAS_ERR_OK ) -#else - if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputWavFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1961,11 +1882,7 @@ static ivas_error initOnFirstGoodFrame( return IVAS_ERR_INVALID_SPLIT_REND_CONFIG; } -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs, splitRendIsarFrameSizeMs, arg.output_Fs, lc3plusHighRes ) ) != IVAS_ERR_OK ) -#else - if ( ( error = split_rend_writer_open( splitRendWriter, arg.outputMdFilename, delayNumSamples_temp[0], delayTimeScale_temp, splitRendCodec, poseCorrection, splitRendCodecFrameSizeMs ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nUnable to open output split rendering metadata file %s\n", arg.outputWavFilename ); return error; @@ -1975,23 +1892,19 @@ static ivas_error initOnFirstGoodFrame( if ( !isSplitCoded ) { -#endif /* Open audio writer and write all previously skipped bad frames now that frame size is known */ if ( ( error = AudioFileWriter_open( ppAfWriter, arg.outputWavFilename, arg.output_Fs, *pNumOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nUnable to open output file %s\n", arg.outputWavFilename ); return error; } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *splitRendWriter != NULL ) { ISAR_SPLIT_REND_BITS_DATA splitRendBitsZero; @@ -2001,12 +1914,8 @@ static ivas_error initOnFirstGoodFrame( splitRendBitsZero.buf_len = 0; splitRendBitsZero.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; splitRendBitsZero.pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE; -#ifdef ISAR_BITSTREAM_UPDATE_LC3PLUS splitRendBitsZero.codec_frame_size_ms = 0; splitRendBitsZero.isar_frame_size_ms = 20; -#else - splitRendBitsZero.codec_frame_size_ms = 20; -#endif if ( split_rend_write_bitstream_to_file( *splitRendWriter, splitRendBitsZero.bits_buf, &splitRendBitsZero.bits_read, &splitRendBitsZero.bits_written ) != IVAS_ERR_OK ) { @@ -2016,19 +1925,10 @@ static ivas_error initOnFirstGoodFrame( } else { -#endif -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *pRemainingDelayNumSamples < *numOutSamples ) -#else - if ( *pRemainingDelayNumSamples < numOutSamples ) -#endif { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) -#else - if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nOutput audio file writer error\n" ); return error; @@ -2037,15 +1937,9 @@ static ivas_error initOnFirstGoodFrame( } else { -#ifdef SPLIT_REND_WITH_HEAD_ROT *pRemainingDelayNumSamples -= *numOutSamples; -#else - *pRemainingDelayNumSamples -= numOutSamples; -#endif } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif } free( zeroBuf ); @@ -2132,7 +2026,6 @@ static ivas_error initOnFirstGoodFrame( } } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( *splitRendWriter != NULL ) { if ( numOutSamples == NULL || vec_pos_len == NULL ) @@ -2152,7 +2045,6 @@ static ivas_error initOnFirstGoodFrame( return error; } } -#endif return IVAS_ERR_OK; } @@ -2171,9 +2063,7 @@ static ivas_error decodeG192( RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, -#ifdef SPLIT_REND_WITH_HEAD_ROT ISAR_SPLIT_REND_BITS_DATA *splitRendBits, -#endif IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ) @@ -2209,7 +2099,6 @@ static ivas_error decodeG192( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; -#ifdef SPLIT_REND_WITH_HEAD_ROT SplitFileReadWrite *splitRendWriter = NULL; int16_t isSplitRend, isSplitCoded; @@ -2224,7 +2113,6 @@ static ivas_error decodeG192( fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_coded_out, code: %d\n", error ); return error; } -#endif IVAS_RENDER_CONFIG_DATA renderConfig; RenderConfigReader *renderConfigReader = NULL; @@ -2383,7 +2271,6 @@ static ivas_error decodeG192( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -2399,7 +2286,6 @@ static ivas_error decodeG192( } else { -#endif for ( i = 0; i < num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) @@ -2408,17 +2294,11 @@ static ivas_error decodeG192( goto cleanup; } } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif for ( i = 0; i < num_subframes; i++ ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2542,7 +2422,6 @@ static ivas_error decodeG192( } } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { if ( ( error = IVAS_DEC_GetSplitBinauralBitstream( hIvasDec, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), splitRendBits, &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) @@ -2556,21 +2435,14 @@ static ivas_error decodeG192( } else { -#endif -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, IVAS_DEC_PCM_INT16, (void *) ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif if ( needNewFrame ) { frame++; @@ -2604,11 +2476,7 @@ static ivas_error decodeG192( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) -#else - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) -#endif { goto cleanup; } @@ -2622,7 +2490,6 @@ static ivas_error decodeG192( /* Write current frame */ if ( decodedGoodFrame ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( isSplitRend ) { if ( split_rend_write_bitstream_to_file( splitRendWriter, splitRendBits->bits_buf, &splitRendBits->bits_read, &splitRendBits->bits_written ) != IVAS_ERR_OK ) @@ -2634,7 +2501,6 @@ static ivas_error decodeG192( if ( !isSplitCoded ) { -#endif if ( delayNumSamples < nOutSamples ) { if ( ( error = AudioFileWriter_write( afWriter, &pcmBuf[delayNumSamples * nOutChannels], nOutSamples * nOutChannels - ( delayNumSamples * nOutChannels ) ) ) != IVAS_ERR_OK ) @@ -2648,9 +2514,7 @@ static ivas_error decodeG192( { delayNumSamples -= nOutSamples; } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif } /* Write ISm metadata to external file(s) */ @@ -2771,11 +2635,7 @@ static ivas_error decodeG192( goto cleanup; } -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternion, Pos[0], 0 ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2783,11 +2643,7 @@ static ivas_error decodeG192( } /* decode and get samples */ -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -2906,18 +2762,14 @@ static ivas_error decodeG192( memset( pcmBuf, 0, delayNumSamples_orig[0] * nOutChannels * sizeof( int16_t ) ); -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( afWriter != NULL ) { -#endif if ( ( error = AudioFileWriter_write( afWriter, pcmBuf, delayNumSamples_orig[0] * nOutChannels ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError writing output file: %s\n", ivas_error_to_string( error ) ); goto cleanup; } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif /*------------------------------------------------------------------------------------------* * Close files and deallocate resources @@ -2928,9 +2780,7 @@ static ivas_error decodeG192( cleanup: RenderConfigReader_close( &renderConfigReader ); -#ifdef SPLIT_REND_WITH_HEAD_ROT split_rend_reader_writer_close( &splitRendWriter ); -#endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); #ifdef DEBUGGING @@ -3282,7 +3132,6 @@ static ivas_error decodeVoIP( { IVAS_QUATERNION Quaternions[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( headRotReader == NULL ) { for ( i = 0; i < num_subframes; i++ ) @@ -3298,7 +3147,6 @@ static ivas_error decodeVoIP( } else { -#endif for ( i = 0; i < num_subframes; i++ ) { if ( ( error = HeadRotationFileReading( headRotReader, &Quaternions[i], &Pos[i] ) ) != IVAS_ERR_OK ) @@ -3308,17 +3156,11 @@ static ivas_error decodeVoIP( goto cleanup; } } -#ifdef SPLIT_REND_WITH_HEAD_ROT } -#endif for ( i = 0; i < num_subframes; i++ ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i, DEFAULT_AXIS ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_FeedHeadTrackData( hIvasDec, Quaternions[i], Pos[i], i ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nIVAS_DEC_FeedHeadTrackData failed: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3405,18 +3247,10 @@ static ivas_error decodeVoIP( /* decode and get samples */ -#ifdef SPLIT_REND_WITH_HEAD_ROT #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) -#endif -#else -#ifdef SUPPORT_JBM_TRACEFILE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK ) -#endif #endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -3453,15 +3287,10 @@ static ivas_error decodeVoIP( /* Once good frame decoded, catch up */ if ( decodedGoodFrame ) { -#ifdef SPLIT_REND_WITH_HEAD_ROT SplitFileReadWrite *splitRendWriter = NULL; if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, NULL, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK ) -#else - if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, nOutSamples, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, - &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj ) ) != IVAS_ERR_OK ) -#endif { goto cleanup; } @@ -3566,11 +3395,7 @@ static ivas_error decodeVoIP( int16_t nSamplesFlushed = 0; /* decode and get samples */ -#ifdef SPLIT_REND_WITH_HEAD_ROT if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) -#else - if ( ( error = IVAS_DEC_Flush( hIvasDec, nOutSamples, pcmBuf, &nSamplesFlushed ) ) != IVAS_ERR_OK ) -#endif { fprintf( stderr, "\nError in IVAS_DEC_VoIP_Flush: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index aed98cbe3b..bb09116de7 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -1714,7 +1714,6 @@ void ivas_spar_dec_upmixer_sf( ivas_spar_dump_signal_wav( output_frame, NULL, output, hSpar->numOutChannels, spar_foa_dec_wav[3], "cldfbSynthesis()" ); #endif - hSpar->slots_rendered += hSpar->subframe_nbslots[hSpar->subframes_rendered]; hSpar->subframes_rendered++; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2c9b2e99d1..8f096dd705 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -38,7 +38,6 @@ #include "cnst.h" #include "ivas_cnst.h" #include "stat_dec.h" -#include "ambi_convert.h" #include "ivas_stat_com.h" #include "ivas_stat_rend.h" @@ -988,12 +987,12 @@ typedef struct decoder_config_structure int16_t Opt_Headrotation; /* indicates whether head-rotation is used */ int16_t Opt_RendConfigCustom; /* indicates whether Renderer configuration custom setup is used */ IVAS_HEAD_ORIENT_TRK_T orientation_tracking; /* indicates orientation tracking type */ - int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ - float non_diegetic_pan_gain; /* non diegetic panning gain*/ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ - int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ - int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ + int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ + float non_diegetic_pan_gain; /* non diegetic panning gain*/ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ + int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ + int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ #ifdef DEBUGGING /* temp. development parameters */ int16_t force_rend; /* forced TD/CLDFB binaural renderer (for ISM and MC) */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 7ce36f86d6..66032833c1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -40,7 +40,6 @@ #include "jbm_jb4sb.h" #include "jbm_pcmdsp_apa.h" #include "jbm_pcmdsp_fifo.h" -#include "ambi_convert.h" #include #include #include diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 4914b59625..5ddcf9a506 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -34,7 +34,6 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" -#include "ambi_convert.h" #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 66656a9273..3962ac055f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -37,7 +37,6 @@ #include "options.h" #include "cnst.h" #include "ivas_cnst.h" -#include "ambi_convert.h" #include "stat_enc.h" #include "ivas_stat_com.h" @@ -1183,6 +1182,7 @@ typedef struct encoder_config_structure int16_t sba_planar; /* Ambisonic (SBA) planar flag */ MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ int16_t ism_extended_metadata_flag; /* flag indicating extended metadata encoding, including radius and orientation (yaw, pitch) in ISM format */ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ int16_t Opt_DTX_ON; /* flag indicating DTX operation */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index e54dfdb803..23e666a7f0 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -562,8 +562,8 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( { return IVAS_ERR_TOO_MANY_INPUTS; } - st_ivas = hIvasEnc->st_ivas; + st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ st_ivas->hEncoderConfig->sba_planar = isPlanar; st_ivas->hEncoderConfig->sba_order = order; -- GitLab From 6d573d584f771929ecf02f6175a195958125de2d Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 09:27:53 +0200 Subject: [PATCH 070/102] fix compile warning --- lib_util/ambi_convert.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 76939aa659..8fa7b5ca58 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -31,7 +31,6 @@ *******************************************************************************************************/ #include "options.h" -#ifdef AMBISONICS_CONVENTIONS #include #include #include "ivas_cnst.h" @@ -350,5 +349,4 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL } return 0; -} -#endif +} \ No newline at end of file -- GitLab From b5db8f0ffc63acdcb511e368b11ee1306a6058e2 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 09:29:13 +0200 Subject: [PATCH 071/102] add ambi_convert.c and ambi_convert.h to lib_util.vcxproj --- Workspace_msvc/lib_util.vcxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 79e5545f3f..4ec7948021 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -101,6 +101,7 @@ + @@ -128,6 +129,7 @@ + -- GitLab From fdcaee463a9d4020df89b220a3e18f822fbb3a25 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 09:40:08 +0200 Subject: [PATCH 072/102] do not scale down channels in format conversions --- lib_util/ambi_convert.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 8fa7b5ca58..a4c817d6b1 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -73,9 +73,6 @@ static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_5_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_, INV_SQRT_7_ }; -static const float N3D_SN3D_SCALING_FACTOR = 1.0f; -static const float SN3D_N3D_SCALING_FACTOR = INV_SQRT_7_; - static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f, 1.0f, 1.0f, 1.0f, @@ -87,10 +84,6 @@ static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float MAXN_SN3D_SCALING_FACTOR = 1.0f; -static const float SN3D_MAXN_SCALING_FACTOR = INV_THREE_OVER_SQRT_5_; - - static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, @@ -101,10 +94,6 @@ static const float FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float FM_SN3D_SCALING_FACTOR = INV_SQRT_2; -static const float SN3D_FM_SCALING_FACTOR = INV_THREE_OVER_SQRT_5_; - - /* ---------------------------- channel re-ordering tables ---------------------------- */ @@ -236,17 +225,14 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; - sf = SN3D_N3D_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; - sf = SN3D_MAXN_SCALING_FACTOR; } else if ( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; - sf = SN3D_FM_SCALING_FACTOR; } else { @@ -258,17 +244,14 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA if ( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; - sf = N3D_SN3D_SCALING_FACTOR; } else if ( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; - sf = MAXN_SN3D_SCALING_FACTOR; } else if ( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; - sf = FM_SN3D_SCALING_FACTOR; } else { @@ -286,7 +269,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA float conversion_factor = conversion_table[i_chan]; for ( i = 0; i < L_FRAME48k; i++ ) { - out[i_chan][i] = sf * in[i_chan][i] * conversion_factor; + out[i_chan][i] = in[i_chan][i] * conversion_factor; } } -- GitLab From f601893c9fddc0666ff78101e263557ca3f88330 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 09:49:10 +0200 Subject: [PATCH 073/102] fix formatting --- lib_util/ambi_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index a4c817d6b1..126eeab1e0 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -332,4 +332,4 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL } return 0; -} \ No newline at end of file +} -- GitLab From 82d214b03220ae53360caaf9603c4088ddf5c62c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 20 Jun 2024 09:56:13 +0200 Subject: [PATCH 074/102] fix compile warning --- lib_util/ambi_convert.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 126eeab1e0..d42f7527de 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -216,7 +216,6 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; const float *conversion_table = 0; - float sf = 1.0f; /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ -- GitLab From 0eb68c065ec91c67a795f8354970f0112c833bf7 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 26 Jun 2024 09:22:45 +0200 Subject: [PATCH 075/102] initialize local variables using the names from the struct --- lib_util/ambi_convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index d42f7527de..53b8e7049f 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -125,8 +125,8 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { assert( order <= 3 ); - AMBI_CHANNEL_ORDER ch_ord_in = 0, ch_ord_out = 0; - AMBI_CHANNEL_NORM ch_norm_in = 0, ch_norm_out = 0; + AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN, ch_ord_out = AMBI_NORM_SN3D; + AMBI_CHANNEL_NORM ch_norm_in = AMBI_CHANNEL_ORDER_ACN, ch_norm_out = AMBI_NORM_SN3D; if ( in_format != AMBI_FMT_ACN_SN3D && out_format != AMBI_FMT_ACN_SN3D ) { -- GitLab From 123f3f513eda71be9b2b09bddba556d0982f2a4e Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 26 Jun 2024 11:56:04 +0200 Subject: [PATCH 076/102] remove IVAS-specific dependencies from ambi_convert.h and ambi_convert.c --- lib_util/ambi_convert.c | 7 +++---- lib_util/ambi_convert.h | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 53b8e7049f..cbb2a3da55 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -29,13 +29,12 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ -#include "options.h" - #include #include -#include "ivas_cnst.h" #include "ambi_convert.h" +#define L_FRAME48k 960 + #define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ #define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ #define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ @@ -84,7 +83,7 @@ static const float MAXN_SN3D[AMBI_MAX_CHANNELS] = { 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, 1.0f, INV_TWO_OVER_SQRT_3_, INV_TWO_OVER_SQRT_3_, INV_SQRT_8_OVER_5_, INV_THREE_OVER_SQRT_5_, INV_SQRT_45_OVER_32_, 1.0f, INV_SQRT_45_OVER_32_, INV_THREE_OVER_SQRT_5_, INV_SQRT_8_OVER_5_ }; -static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2, +static const float SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2_, 1.0f, 1.0f, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, 1.0f, TWO_OVER_SQRT_3_, TWO_OVER_SQRT_3_, SQRT_8_OVER_5_, THREE_OVER_SQRT_5_, SQRT_45_OVER_32_, 1.0f, SQRT_45_OVER_32_, THREE_OVER_SQRT_5_, SQRT_8_OVER_5_ }; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 49fdc38838..c61bd79177 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -33,7 +33,6 @@ #ifndef AMBI_CONVERT_H #define AMBI_CONVERT_H -#include "options.h" #include typedef enum -- GitLab From 0e1ee7cdfededff3be5a19977339e3f6b85a61c7 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 26 Jun 2024 12:22:56 +0200 Subject: [PATCH 077/102] add standalone ambisonics converter program ambi_converter.c --- apps/ambi_converter.c | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 apps/ambi_converter.c diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c new file mode 100644 index 0000000000..d572b0e722 --- /dev/null +++ b/apps/ambi_converter.c @@ -0,0 +1,110 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ +#include +#include +#include +#include "tinywavein_c.h" +#include "tinywaveout_c.h" +#include "ambi_convert.h" + +#define L_FRAME48k 960 +#define MAX_CHANNELS 16 + +int main(int argc, char* argv[]) +{ + + WAVEFILEIN *wavFile_in; + WAVEFILEOUT *wavFile_out; + char* fileName_in, *fileName_out; + + uint32_t samplingRate; + uint32_t samplesInFile; + uint32_t numSamples = L_FRAME48k; + uint32_t numSamplesRead32 = 0; + + int16_t bps; + int16_t samples[L_FRAME48k*MAX_CHANNELS]; + int16_t order = 0; + int16_t numChannels; + + AMBI_FMT in_format, out_format; + + float samples_f_in[L_FRAME48k*MAX_CHANNELS]; + float samples_f_out[L_FRAME48k*MAX_CHANNELS]; + float *in[MAX_CHANNELS], *out[MAX_CHANNELS]; + + for(int16_t j=0;j 0 && order <=3 ); + + while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) != __TWI_SUCCESS ) + { + int16_t err = 0; + for (int16_t i=0;i Date: Wed, 26 Jun 2024 14:26:05 +0200 Subject: [PATCH 078/102] fix bugs in apps/ambi_converter.c --- apps/ambi_converter.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index d572b0e722..eddcf06e19 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -79,20 +79,27 @@ int main(int argc, char* argv[]) order = (int16_t)sqrtf(numChannels) - 1; assert( order > 0 && order <=3 ); - while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) != __TWI_SUCCESS ) + + while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int16_t err = 0; - for (int16_t i=0;i Date: Wed, 26 Jun 2024 14:39:44 +0200 Subject: [PATCH 079/102] fix typo in lib_util/ambi_convert.c --- lib_util/ambi_convert.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index cbb2a3da55..700d7db12e 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -216,8 +216,7 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA int16_t i_chan, i; const float *conversion_table = 0; - /* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */ - + /* conversion factors are applied on the channels assuming that they are still/already in ACN order */ if ( in_format == AMBI_NORM_SN3D ) { if ( out_format == AMBI_NORM_N3D ) -- GitLab From 4d788620a3f99c8082f0f8d83ababb55023b4c0a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 26 Jun 2024 15:28:41 +0200 Subject: [PATCH 080/102] fix if condition in renormalize_channels --- lib_util/ambi_convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index cbb2a3da55..2a737c9b71 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -287,7 +287,7 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL { idx_table = REORDER_ACN_FM; } - if ( out_format == AMBI_CHANNEL_ORDER_SID ) + else if ( out_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_ACN_SID; } @@ -302,7 +302,7 @@ int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL { idx_table = REORDER_FM_ACN; } - if ( in_format == AMBI_CHANNEL_ORDER_SID ) + else if ( in_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_SID_ACN; } -- GitLab From 49637baf521df429de9faeb8dab803362c98ffd6 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 28 Jun 2024 11:29:39 +0200 Subject: [PATCH 081/102] fix bug in channel reordering --- lib_util/ambi_convert.c | 50 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index b37a984327..093cf6142c 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -31,6 +31,7 @@ *******************************************************************************************************/ #include #include +#include #include "ambi_convert.h" #define L_FRAME48k 960 @@ -123,15 +124,24 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) { - assert( order <= 3 ); + + float tmp[AMBI_MAX_CHANNELS*L_FRAME48k]; + float *p_tmp[AMBI_MAX_CHANNELS]; AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN, ch_ord_out = AMBI_NORM_SN3D; AMBI_CHANNEL_NORM ch_norm_in = AMBI_CHANNEL_ORDER_ACN, ch_norm_out = AMBI_NORM_SN3D; + assert( order <= 3 ); + if ( in_format != AMBI_FMT_ACN_SN3D && out_format != AMBI_FMT_ACN_SN3D ) { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); } + for(int16_t j=0;j Date: Fri, 28 Jun 2024 12:04:56 +0200 Subject: [PATCH 082/102] add format-number printout to ambi_converter.c --- apps/ambi_converter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index eddcf06e19..8fdb3573fc 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -73,6 +73,8 @@ int main(int argc, char* argv[]) in_format = atoi(argv[3]); out_format = atoi(argv[4]); + printf("In %d, Out: %d\n",in_format,out_format); + wavFile_in = OpenWav( fileName_in, &samplingRate, &numChannels, &samplesInFile, &bps ); wavFile_out = CreateWav( fileName_out, samplingRate, numChannels, 16 ); -- GitLab From 62fc6aca3711026cbb1f3abecfbb0e2dd00d7d65 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 28 Jun 2024 12:24:40 +0200 Subject: [PATCH 083/102] fix logic in convert_ambi_format --- lib_util/ambi_convert.c | 82 +++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 093cf6142c..416b3e5c0a 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -203,52 +203,54 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT } if ( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + { + if ( ch_ord_in != ch_ord_out ) + { + renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); + reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ); + } + else + { + renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + } + } + else if( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); + reorder_channels( in, out, order, ch_ord_in, ch_ord_out ); } - -#if 0 - { - static FILE* f_foa = 0; - if (f_foa == 0) - f_foa = fopen("renorm.raw","wb"); - - for (int16_t j=0; j < 960;j++) - { - for ( int n = 0; n < 16; n++) - { - int16_t s1 = out[n][j]; - fwrite(&s1,sizeof(int16_t),1,f_foa); - } - } - } -#endif - - if ( ch_ord_in != ch_ord_out ) + else if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + { + if ( ch_ord_in != ch_ord_out ) + { + reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ); + renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ); + } + else + { + renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + } + } + else if ( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ); + reorder_channels( in, out, order, ch_ord_in, ch_ord_out ); } + else if ( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D) + { + int16_t i_chan = 0; + int16_t n_chan = ( order + 1 ) * ( order + 1 ); -#if 0 - { - static FILE* f_foa = 0; - if (f_foa == 0) - f_foa = fopen("reorder.raw","wb"); - - for (int16_t j=0; j < 960;j++) - { - for ( int n = 0; n < 16; n++) - { - int16_t s1 = out[n][j]; - fwrite(&s1,sizeof(int16_t),1,f_foa); - } - } - } -#endif - - if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + int16_t i = 0; + for ( i = 0; i < L_FRAME48k; i++ ) + { + out[i_chan][i] = in[i_chan][i]; + } + } + } + else { - renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + assert ( 0 && "This should never happen!"); } return 0; -- GitLab From efafa468cfc62336c528a2cab466273bcc2bdebc Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 28 Jun 2024 13:46:43 +0200 Subject: [PATCH 084/102] fix compiler warning --- lib_util/ambi_convert.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 416b3e5c0a..28a49fdba8 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -127,8 +127,12 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT float tmp[AMBI_MAX_CHANNELS*L_FRAME48k]; float *p_tmp[AMBI_MAX_CHANNELS]; - AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN, ch_ord_out = AMBI_NORM_SN3D; - AMBI_CHANNEL_NORM ch_norm_in = AMBI_CHANNEL_ORDER_ACN, ch_norm_out = AMBI_NORM_SN3D; + + AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN; + AMBI_CHANNEL_ORDER ch_ord_out = AMBI_CHANNEL_ORDER_ACN; + + AMBI_CHANNEL_NORM ch_norm_in = AMBI_NORM_SN3D; + AMBI_CHANNEL_NORM ch_norm_out = AMBI_NORM_SN3D; assert( order <= 3 ); -- GitLab From dce7def874026657523c011da0b42ca0bc4ac87f Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 28 Jun 2024 13:54:54 +0200 Subject: [PATCH 085/102] fix formatting --- apps/ambi_converter.c | 48 ++++++++++++++++++++--------------------- lib_util/ambi_convert.c | 20 ++++++++--------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 8fdb3573fc..45f12acd45 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -36,50 +36,50 @@ #include "tinywaveout_c.h" #include "ambi_convert.h" -#define L_FRAME48k 960 +#define L_FRAME48k 960 #define MAX_CHANNELS 16 -int main(int argc, char* argv[]) +int main( int argc, char *argv[] ) { WAVEFILEIN *wavFile_in; WAVEFILEOUT *wavFile_out; - char* fileName_in, *fileName_out; - + char *fileName_in, *fileName_out; + uint32_t samplingRate; uint32_t samplesInFile; uint32_t numSamples = L_FRAME48k; uint32_t numSamplesRead32 = 0; - + int16_t bps; - int16_t samples[L_FRAME48k*MAX_CHANNELS]; + int16_t samples[L_FRAME48k * MAX_CHANNELS]; int16_t order = 0; int16_t numChannels; AMBI_FMT in_format, out_format; - float samples_f_in[L_FRAME48k*MAX_CHANNELS]; - float samples_f_out[L_FRAME48k*MAX_CHANNELS]; + float samples_f_in[L_FRAME48k * MAX_CHANNELS]; + float samples_f_out[L_FRAME48k * MAX_CHANNELS]; float *in[MAX_CHANNELS], *out[MAX_CHANNELS]; - for(int16_t j=0;j 0 && order <=3 ); + order = (int16_t) sqrtf( numChannels ) - 1; + assert( order > 0 && order <= 3 ); while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) @@ -91,21 +91,21 @@ int main(int argc, char* argv[]) break; } - for (int16_t i=0;i Date: Fri, 28 Jun 2024 14:27:42 +0200 Subject: [PATCH 086/102] delete unused test vectors stv3OA48c_FuMa.wav, stv3OA48c_N3D.wav, stv3OA48c_SN3D-SID.wav --- scripts/testv/stv3OA48c_FuMa.wav | 3 --- scripts/testv/stv3OA48c_N3D.wav | 3 --- scripts/testv/stv3OA48c_SN3D-SID.wav | 3 --- 3 files changed, 9 deletions(-) delete mode 100644 scripts/testv/stv3OA48c_FuMa.wav delete mode 100644 scripts/testv/stv3OA48c_N3D.wav delete mode 100644 scripts/testv/stv3OA48c_SN3D-SID.wav diff --git a/scripts/testv/stv3OA48c_FuMa.wav b/scripts/testv/stv3OA48c_FuMa.wav deleted file mode 100644 index 6b52c739ce..0000000000 --- a/scripts/testv/stv3OA48c_FuMa.wav +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:95f21ed4f2134ff6a43e2f3a1654396e1c02bc5e78f3ddd69071adb16567cb53 -size 30720844 diff --git a/scripts/testv/stv3OA48c_N3D.wav b/scripts/testv/stv3OA48c_N3D.wav deleted file mode 100644 index 150b8a91d9..0000000000 --- a/scripts/testv/stv3OA48c_N3D.wav +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:68c29e8be1afe7cac05914a6152438f86a417b30e88241eb25b061de14a98b73 -size 30720844 diff --git a/scripts/testv/stv3OA48c_SN3D-SID.wav b/scripts/testv/stv3OA48c_SN3D-SID.wav deleted file mode 100644 index 6e46a91732..0000000000 --- a/scripts/testv/stv3OA48c_SN3D-SID.wav +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:363204e18b68f242fd97d76fbd0a911d9b8a479ecf9b68ffaa47114ddc2ab9af -size 30720844 -- GitLab From 81caf0df5a00e045891deded02edb4bfcd6e4b9c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 28 Jun 2024 15:12:54 +0200 Subject: [PATCH 087/102] fix length of output file --- apps/ambi_converter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 45f12acd45..17aaf3ac24 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -109,7 +109,7 @@ int main( int argc, char *argv[] ) } } - err = WriteWavShort( wavFile_out, samples, numSamples ); + err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ); numSamplesRead32 = 0; } -- GitLab From 4b3e2eb937ad4dfcec781d7dd00ba7d252837b3d Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 10:39:33 +0200 Subject: [PATCH 088/102] move definition of L_FRAME48k and AMBI_MAX_CHANNELS to lib_util/ambi_convert.h --- lib_util/ambi_convert.c | 5 ----- lib_util/ambi_convert.h | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 5e2ab047e7..aedf4aaa88 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -34,8 +34,6 @@ #include #include "ambi_convert.h" -#define L_FRAME48k 960 - #define SQRT_2_ 1.4142135f /* sqrtf(2.0f) */ #define SQRT_3_ 1.7320508f /* sqrtf(3.0f) */ #define SQRT_5_ 2.2360679f /* sqrtf(5.0f) */ @@ -56,9 +54,6 @@ #define INV_SQRT_8_OVER_5_ 0.7905694f /* 1.0f/INV_SQRT_8_OVER_5_ */ #define INV_SQRT_45_OVER_32_ 0.8432740f /* 1.0f/SQRT_45_OVER_32_ */ -#define AMBI_MAX_CHANNELS 16 - - /* -------------------------------- normalization conversion tables -------------------------------- */ diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index c61bd79177..39b65f2b88 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -35,6 +35,9 @@ #include +#define L_FRAME48k 960 +#define AMBI_MAX_CHANNELS 16 + typedef enum { AMBI_FMT_ACN_SN3D = 0, -- GitLab From e6f667a7831ea39b6a47b24c70f12e591bdfd848 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 10:43:41 +0200 Subject: [PATCH 089/102] use constants from ambi_convert.h in ambi_converter.c --- apps/ambi_converter.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 17aaf3ac24..4f44e1c00c 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -36,8 +36,6 @@ #include "tinywaveout_c.h" #include "ambi_convert.h" -#define L_FRAME48k 960 -#define MAX_CHANNELS 16 int main( int argc, char *argv[] ) { @@ -52,17 +50,17 @@ int main( int argc, char *argv[] ) uint32_t numSamplesRead32 = 0; int16_t bps; - int16_t samples[L_FRAME48k * MAX_CHANNELS]; + int16_t samples[L_FRAME48k * AMBI_MAX_CHANNELS]; int16_t order = 0; int16_t numChannels; AMBI_FMT in_format, out_format; - float samples_f_in[L_FRAME48k * MAX_CHANNELS]; - float samples_f_out[L_FRAME48k * MAX_CHANNELS]; - float *in[MAX_CHANNELS], *out[MAX_CHANNELS]; + float samples_f_in[L_FRAME48k * AMBI_MAX_CHANNELS]; + float samples_f_out[L_FRAME48k * AMBI_MAX_CHANNELS]; + float *in[AMBI_MAX_CHANNELS], *out[AMBI_MAX_CHANNELS]; - for ( int16_t j = 0; j < MAX_CHANNELS; j++ ) + for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) { in[j] = &samples_f_in[j * L_FRAME48k]; out[j] = &samples_f_out[j * L_FRAME48k]; -- GitLab From 2d0c2275463238dc7b9f5d4d5419250dba0bfc6a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 11:24:40 +0200 Subject: [PATCH 090/102] fix formatting --- lib_util/ambi_convert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 39b65f2b88..e969f2b25d 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -35,7 +35,7 @@ #include -#define L_FRAME48k 960 +#define L_FRAME48k 960 #define AMBI_MAX_CHANNELS 16 typedef enum -- GitLab From 00c1f94e267e0a9f412cc38115307e86c5122e88 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 12:03:02 +0200 Subject: [PATCH 091/102] add descriptions to function arguments in lib_util/ambi_convert.c and lib_util/ambi_convert.h --- lib_util/ambi_convert.c | 24 +++++++++++++++++++++--- lib_util/ambi_convert.h | 29 +++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index aedf4aaa88..20a043b714 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -117,7 +117,13 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, API functions for the conversion ---------------------------------- */ -int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ) +int16_t convert_ambi_format( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ +) { float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; @@ -255,7 +261,13 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT return 0; } -int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ) +int16_t renormalize_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ +) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; @@ -318,7 +330,13 @@ int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHA return 0; } -int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ) +int16_t reorder_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ +) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); int16_t i_chan, i; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index e969f2b25d..13d09cf56f 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -63,10 +63,27 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; -int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format ); - -int16_t renormalize_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_NORM in_format, AMBI_CHANNEL_NORM out_format ); - -int16_t reorder_channels( float *in[], float *out[], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format ); - +int16_t convert_ambi_format( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ +); + +int16_t renormalize_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ +); + +int16_t reorder_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ +); #endif -- GitLab From a256c3a37c7001b36e286c553a535ad9951628b2 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 12:04:01 +0200 Subject: [PATCH 092/102] fix formatting --- lib_util/ambi_convert.c | 36 ++++++++++++++++++------------------ lib_util/ambi_convert.h | 30 +++++++++++++++--------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 20a043b714..91e686612d 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -117,12 +117,12 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, API functions for the conversion ---------------------------------- */ -int16_t convert_ambi_format( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ +int16_t convert_ambi_format( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ ) { @@ -261,12 +261,12 @@ int16_t convert_ambi_format( return 0; } -int16_t renormalize_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ +int16_t renormalize_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); @@ -330,12 +330,12 @@ int16_t renormalize_channels( return 0; } -int16_t reorder_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ +int16_t reorder_channels( + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 13d09cf56f..842283c1cd 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -64,26 +64,26 @@ typedef enum } AMBI_CHANNEL_ORDER; int16_t convert_ambi_format( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ ); int16_t renormalize_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); int16_t reorder_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ ); #endif -- GitLab From 3a3dd65eb18c70fe62b416dbf5682536d7283dbb Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 12:22:13 +0200 Subject: [PATCH 093/102] add more detailes functions descriptions --- lib_util/ambi_convert.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 91e686612d..961b48d2a3 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -117,6 +117,12 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, API functions for the conversion ---------------------------------- */ +/*-------------------------------------------------------------------------* +* convert_ambi_format() +* +* Convert signal between ACN-SN3D and other common ambisonics conventions +--------------------------------------------------------------------------*/ + int16_t convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ @@ -261,6 +267,12 @@ int16_t convert_ambi_format( return 0; } +/*-------------------------------------------------------------------------* +* renormalize_channels() +* +* Rescale audio channels according to the selected ambisonics convention +--------------------------------------------------------------------------*/ + int16_t renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ @@ -330,6 +342,12 @@ int16_t renormalize_channels( return 0; } +/*-------------------------------------------------------------------------* +* reorder_channels() +* +* Reorder channels according to the selected ambisonics convention +--------------------------------------------------------------------------*/ + int16_t reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ -- GitLab From 9b774f294ca9501b66b444dcfcf8c66403c685d3 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 13:08:39 +0200 Subject: [PATCH 094/102] implement error handling in convert_ambi_format --- apps/ambi_converter.c | 14 ++++++-- lib_util/ambi_convert.c | 71 ++++++++++++++++++++++++++++------------- lib_util/ambi_convert.h | 12 +++++-- 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 4f44e1c00c..d7c981c214 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -79,7 +79,6 @@ int main( int argc, char *argv[] ) order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); - while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int16_t err = 0; @@ -97,7 +96,12 @@ int main( int argc, char *argv[] ) } } - err = convert_ambi_format( in, out, order, in_format, out_format ); + if ( (err = convert_ambi_format( in, out, order, in_format, out_format )) != 0 ) + { + printf("Error converting the input signal!\n"); + return err; + } + for ( int16_t i = 0; i < numSamplesRead32; i++ ) { @@ -107,7 +111,11 @@ int main( int argc, char *argv[] ) } } - err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ); + if ( (err = WriteWavShort( wavFile_out, samples, numSamplesRead32 )) != __TWO_SUCCESS ) + { + printf("Error writing output wave file!\n"); + return err; + } numSamplesRead32 = 0; } diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 961b48d2a3..b5cef0ef2e 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -123,7 +123,7 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, * Convert signal between ACN-SN3D and other common ambisonics conventions --------------------------------------------------------------------------*/ -int16_t convert_ambi_format( +AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ @@ -134,6 +134,7 @@ int16_t convert_ambi_format( float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; float *p_tmp[AMBI_MAX_CHANNELS]; + AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN; AMBI_CHANNEL_ORDER ch_ord_out = AMBI_CHANNEL_ORDER_ACN; @@ -180,7 +181,7 @@ int16_t convert_ambi_format( ch_norm_in = AMBI_NORM_N3D; break; default: - assert( 0 && "Unsupported in_format!" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } switch ( out_format ) @@ -210,40 +211,64 @@ int16_t convert_ambi_format( ch_norm_out = AMBI_NORM_N3D; break; default: - assert( 0 && "Unsupported out_format!" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } if ( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_out ) { - renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); - reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ); + if( (err = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK ) + { + return err; + } + if( (err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK ) + { + return err; + } } else { - renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + if (( err=renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) != AMBI_CONVERT_OK )) + { + return err; + } } } else if ( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - reorder_channels( in, out, order, ch_ord_in, ch_ord_out ); + if ((err=reorder_channels( in, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) + { + return err; + } } else if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_out ) { - reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ); - renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ); + if (( err = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) + { + return err; + } + if (( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK) + { + return err; + } } else { - renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + if ( (err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK) + { + return err; + } } } else if ( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - reorder_channels( in, out, order, ch_ord_in, ch_ord_out ); + if ( (err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) + { + return err; + } } else if ( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) { @@ -264,7 +289,7 @@ int16_t convert_ambi_format( assert( 0 && "This should never happen!" ); } - return 0; + return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* @@ -273,7 +298,7 @@ int16_t convert_ambi_format( * Rescale audio channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ -int16_t renormalize_channels( +AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ @@ -302,7 +327,7 @@ int16_t renormalize_channels( } else { - assert( 0 && "Unsupported conversion" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) @@ -321,12 +346,12 @@ int16_t renormalize_channels( } else { - assert( 0 && "Unsupported conversion" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { - assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } @@ -339,7 +364,7 @@ int16_t renormalize_channels( } } - return 0; + return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* @@ -348,7 +373,7 @@ int16_t renormalize_channels( * Reorder channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ -int16_t reorder_channels( +AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ @@ -373,8 +398,8 @@ int16_t reorder_channels( } else { - assert( 0 && "Unsupported conversion" ); - } + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) { @@ -388,12 +413,12 @@ int16_t reorder_channels( } else { - assert( 0 && "Unsupported conversion" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { - assert( 0 && "Conversion only supported to and from ACN-SN3D" ); + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i = 0; i < L_FRAME48k; i++ ) @@ -409,5 +434,5 @@ int16_t reorder_channels( } } - return 0; + return AMBI_CONVERT_OK; } diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 842283c1cd..13acbb7d33 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -63,7 +63,13 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; -int16_t convert_ambi_format( +typedef enum +{ + AMBI_CONVERT_OK = 0, + AMBI_CONVERT_UNSUPPORTED_CONVERSION +} AMBI_CONVERT_ERROR; + +AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ @@ -71,7 +77,7 @@ int16_t convert_ambi_format( AMBI_FMT out_format /* i: output ambisonics format */ ); -int16_t renormalize_channels( +AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ @@ -79,7 +85,7 @@ int16_t renormalize_channels( AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); -int16_t reorder_channels( +AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ -- GitLab From c6a905b02a7d4c85f25259e4846df5c9aac0738d Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 13:09:48 +0200 Subject: [PATCH 095/102] fix formatting --- apps/ambi_converter.c | 8 ++--- lib_util/ambi_convert.c | 72 ++++++++++++++++++++--------------------- lib_util/ambi_convert.h | 4 +-- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index d7c981c214..60e8848261 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -96,9 +96,9 @@ int main( int argc, char *argv[] ) } } - if ( (err = convert_ambi_format( in, out, order, in_format, out_format )) != 0 ) + if ( ( err = convert_ambi_format( in, out, order, in_format, out_format ) ) != 0 ) { - printf("Error converting the input signal!\n"); + printf( "Error converting the input signal!\n" ); return err; } @@ -111,9 +111,9 @@ int main( int argc, char *argv[] ) } } - if ( (err = WriteWavShort( wavFile_out, samples, numSamplesRead32 )) != __TWO_SUCCESS ) + if ( ( err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ) ) != __TWO_SUCCESS ) { - printf("Error writing output wave file!\n"); + printf( "Error writing output wave file!\n" ); return err; } diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index b5cef0ef2e..dfddd82bf3 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -134,7 +134,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; float *p_tmp[AMBI_MAX_CHANNELS]; - AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; + AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN; AMBI_CHANNEL_ORDER ch_ord_out = AMBI_CHANNEL_ORDER_ACN; @@ -218,57 +218,57 @@ AMBI_CONVERT_ERROR convert_ambi_format( { if ( ch_ord_in != ch_ord_out ) { - if( (err = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK ) - { - return err; - } - if( (err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK ) - { - return err; - } + if ( ( err = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } + if ( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } } else { - if (( err=renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) != AMBI_CONVERT_OK )) - { - return err; - } + if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) != AMBI_CONVERT_OK ) ) + { + return err; + } } } else if ( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - if ((err=reorder_channels( in, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) - { - return err; - } + if ( ( err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } } else if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_out ) { - if (( err = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) - { - return err; - } - if (( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK) - { - return err; - } + if ( ( err = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } + if ( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } } else { - if ( (err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out )) != AMBI_CONVERT_OK) - { - return err; - } + if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } } } else if ( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - if ( (err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out )) != AMBI_CONVERT_OK) - { - return err; - } + if ( ( err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + { + return err; + } } else if ( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) { @@ -327,7 +327,7 @@ AMBI_CONVERT_ERROR renormalize_channels( } else { - return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) @@ -398,8 +398,8 @@ AMBI_CONVERT_ERROR reorder_channels( } else { - return AMBI_CONVERT_UNSUPPORTED_CONVERSION; - } + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) { diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 13acbb7d33..7b3093c5d3 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -65,8 +65,8 @@ typedef enum typedef enum { - AMBI_CONVERT_OK = 0, - AMBI_CONVERT_UNSUPPORTED_CONVERSION + AMBI_CONVERT_OK = 0, + AMBI_CONVERT_UNSUPPORTED_CONVERSION } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( -- GitLab From d116e642f280df93c9867fad7589b5937dc5bb41 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 13:18:29 +0200 Subject: [PATCH 096/102] fix compiler warning --- lib_util/ambi_convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index dfddd82bf3..92711b8e61 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -229,7 +229,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } else { - if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) != AMBI_CONVERT_OK ) ) + if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) { return err; } -- GitLab From e0f504dd165e500f1e562dfbd34acb488a96159a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 13:28:54 +0200 Subject: [PATCH 097/102] check if wave files have been opened sucessfully in the converter program --- apps/ambi_converter.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 60e8848261..d4210932c7 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -74,7 +74,18 @@ int main( int argc, char *argv[] ) printf( "In %d, Out: %d\n", in_format, out_format ); wavFile_in = OpenWav( fileName_in, &samplingRate, &numChannels, &samplesInFile, &bps ); + if ( !wavFile_in ) + { + fprintf( stderr, "Failed to open input wav file: %s\n", fileName_in ); + return -1; + } + wavFile_out = CreateWav( fileName_out, samplingRate, numChannels, 16 ); + if ( !wavFile_out ) + { + fprintf( stderr, "Failed to open output wav file: %s\n", fileName_out ); + return -1; + } order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); -- GitLab From 4b9756740f946a33655679fb311297b76d5bf967 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 13:38:55 +0200 Subject: [PATCH 098/102] move apps/ambi_converter.c -> scripts/ambi_converter.c --- {apps => scripts}/ambi_converter.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {apps => scripts}/ambi_converter.c (100%) diff --git a/apps/ambi_converter.c b/scripts/ambi_converter.c similarity index 100% rename from apps/ambi_converter.c rename to scripts/ambi_converter.c -- GitLab From d3fcd8eb389b3f24c2afb292ba5f469615d0bc09 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 14:38:45 +0200 Subject: [PATCH 099/102] add description to ambisonics converter program --- scripts/ambi_converter.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/ambi_converter.c b/scripts/ambi_converter.c index d4210932c7..eb02467ac6 100644 --- a/scripts/ambi_converter.c +++ b/scripts/ambi_converter.c @@ -36,6 +36,11 @@ #include "tinywaveout_c.h" #include "ambi_convert.h" +/*-------------------------------------------------------------------------------------* +* Ambisonics converter program +* +* gcc ambi_converter.c ../lib_util/ambi_convert.c -I../lib_util/ -lm -o ambi_converter +*--------------------------------------------------------------------------------------*/ int main( int argc, char *argv[] ) { @@ -66,6 +71,26 @@ int main( int argc, char *argv[] ) out[j] = &samples_f_out[j * L_FRAME48k]; } + if( argc != 5 ) + { + printf("Ambisonics converter program\n"); + printf("----------------------------------------------------------------------------------\n"); + printf("Usage:\n"); + printf("./ambi_conveter input_file output_file input_convention output_convention\n"); + printf("\n"); + printf("input_convention and output convention must be an integer number in [0,5]\n"); + printf("the following conventions are supported:\n"); + printf("0 : ACN-SN3D\n"); + printf("1 : ACN-N3D\n"); + printf("2 : FuMa-MaxN\n"); + printf("3 : FuMa-FuMa\n"); + printf("4 : SID-SN3D\n"); + printf("5 : SID-N3D\n"); + printf("\n"); + printf("Either the input or the output convention must always be ACN-SN3D!\n"); + return -1; + } + fileName_in = argv[1]; fileName_out = argv[2]; in_format = atoi( argv[3] ); -- GitLab From d4307584378af123f4c6b404180754558fce9019 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 14:39:25 +0200 Subject: [PATCH 100/102] fix formatting --- scripts/ambi_converter.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/ambi_converter.c b/scripts/ambi_converter.c index eb02467ac6..9bb6d06f2b 100644 --- a/scripts/ambi_converter.c +++ b/scripts/ambi_converter.c @@ -37,10 +37,10 @@ #include "ambi_convert.h" /*-------------------------------------------------------------------------------------* -* Ambisonics converter program -* -* gcc ambi_converter.c ../lib_util/ambi_convert.c -I../lib_util/ -lm -o ambi_converter -*--------------------------------------------------------------------------------------*/ + * Ambisonics converter program + * + * gcc ambi_converter.c ../lib_util/ambi_convert.c -I../lib_util/ -lm -o ambi_converter + *--------------------------------------------------------------------------------------*/ int main( int argc, char *argv[] ) { @@ -71,23 +71,23 @@ int main( int argc, char *argv[] ) out[j] = &samples_f_out[j * L_FRAME48k]; } - if( argc != 5 ) + if ( argc != 5 ) { - printf("Ambisonics converter program\n"); - printf("----------------------------------------------------------------------------------\n"); - printf("Usage:\n"); - printf("./ambi_conveter input_file output_file input_convention output_convention\n"); - printf("\n"); - printf("input_convention and output convention must be an integer number in [0,5]\n"); - printf("the following conventions are supported:\n"); - printf("0 : ACN-SN3D\n"); - printf("1 : ACN-N3D\n"); - printf("2 : FuMa-MaxN\n"); - printf("3 : FuMa-FuMa\n"); - printf("4 : SID-SN3D\n"); - printf("5 : SID-N3D\n"); - printf("\n"); - printf("Either the input or the output convention must always be ACN-SN3D!\n"); + printf( "Ambisonics converter program\n" ); + printf( "----------------------------------------------------------------------------------\n" ); + printf( "Usage:\n" ); + printf( "./ambi_conveter input_file output_file input_convention output_convention\n" ); + printf( "\n" ); + printf( "input_convention and output convention must be an integer number in [0,5]\n" ); + printf( "the following conventions are supported:\n" ); + printf( "0 : ACN-SN3D\n" ); + printf( "1 : ACN-N3D\n" ); + printf( "2 : FuMa-MaxN\n" ); + printf( "3 : FuMa-FuMa\n" ); + printf( "4 : SID-SN3D\n" ); + printf( "5 : SID-N3D\n" ); + printf( "\n" ); + printf( "Either the input or the output convention must always be ACN-SN3D!\n" ); return -1; } -- GitLab From b86613774f9182940ba565b0c345917663c04a12 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 17:28:22 +0200 Subject: [PATCH 101/102] implement clipping detection in the ambisonics converter program --- scripts/ambi_converter.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/ambi_converter.c b/scripts/ambi_converter.c index 9bb6d06f2b..67ba451970 100644 --- a/scripts/ambi_converter.c +++ b/scripts/ambi_converter.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "tinywavein_c.h" #include "tinywaveout_c.h" #include "ambi_convert.h" @@ -53,6 +54,7 @@ int main( int argc, char *argv[] ) uint32_t samplesInFile; uint32_t numSamples = L_FRAME48k; uint32_t numSamplesRead32 = 0; + uint32_t numSamplesClipped = 0; int16_t bps; int16_t samples[L_FRAME48k * AMBI_MAX_CHANNELS]; @@ -143,7 +145,23 @@ int main( int argc, char *argv[] ) { for ( int16_t j = 0; j < numChannels; j++ ) { - samples[i * numChannels + j] = (int16_t) out[j][i]; + int s1_i; + float s1 = out[j][i]; + if ( s1 < INT16_MIN ) + { + s1_i = INT16_MIN; + numSamplesClipped++; + } + else if ( s1 > INT16_MAX ) + { + s1_i = INT16_MAX; + numSamplesClipped++; + } + else + { + s1_i = (int16_t) s1; + } + samples[i * numChannels + j] = s1_i; } } -- GitLab From ecbfde338890595ed227c203c74b7d13873fbf62 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 3 Jul 2024 17:30:38 +0200 Subject: [PATCH 102/102] print clipping warning --- scripts/ambi_converter.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/ambi_converter.c b/scripts/ambi_converter.c index 67ba451970..087e90a3fd 100644 --- a/scripts/ambi_converter.c +++ b/scripts/ambi_converter.c @@ -177,5 +177,10 @@ int main( int argc, char *argv[] ) CloseWav( wavFile_out ); CloseWavIn( wavFile_in ); + if ( numSamplesClipped ) + { + printf( "Warning: %d samples have clipped!\n", numSamplesClipped ); + } + return 0; } -- GitLab