From 44eb648b28f366e7c962a587d049910e5a374a8d Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 29 Aug 2025 10:26:29 +0200 Subject: [PATCH 01/19] added a fix-point version of the ambisonics converter. --- lib_util/ambi_convert.c | 448 ++++++++++++++++++++++++++++++++++++++++ lib_util/ambi_convert.h | 95 +++++++++ 2 files changed, 543 insertions(+) create mode 100644 lib_util/ambi_convert.c create mode 100644 lib_util/ambi_convert.h diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c new file mode 100644 index 000000000..05814651f --- /dev/null +++ b/lib_util/ambi_convert.c @@ -0,0 +1,448 @@ +/****************************************************************************************************** + + (C) 2022-2025 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 "ambi_convert.h" + +#define THISQ Q29 + +#define ONE_1_Q29 536870912l /* 1.0f */ + +#define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ +#define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ +#define SQRT_5_Q29 1200479872l /* sqrtf(5.0f) */ +#define SQRT_7_Q29 1420426880l /* sqrtf(7.0f) */ + +#define INV_SQRT_2_Q29 379625024l /* 1.0f/sqrtf(2.0f) */ +#define INV_SQRT_3_Q29 309962528l /* 1.0f/sqrtf(3.0f) */ +#define INV_SQRT_5_Q29 240095920l /* 1.0f/sqrtf(5.0f) */ +#define INV_SQRT_7_Q29 202918096l /* 1.0f/sqrtf(7.0f) */ + +#define TWO_OVER_SQRT_3_Q29 619925120l /* 2.0f/sqrtf(3.0f) */ +#define THREE_OVER_SQRT_5_Q29 720287936l /* 3.0f/sqrtf(5.0f) */ +#define SQRT_8_OVER_5_Q29 679093952l /* sqrtf(8.0f/5.0f) */ +#define SQRT_45_OVER_32_Q29 636650560l /* sqrtf(45.0f/32.0f) */ + +#define INV_TWO_OVER_SQRT_3_Q29 464943840l /* 1.0f/TWO_OVER_SQRT_3_Q29 */ +#define INV_THREE_OVER_SQRT_5_Q29 400159968l /* 1.0f/THREE_OVER_SQRT_5_Q29 */ +#define INV_SQRT_8_OVER_5_Q29 424433728l /* 1.0f/INV_SQRT_8_OVER_5_Q29 */ +#define INV_SQRT_45_OVER_32_Q29 452729280l /* 1.0f/SQRT_45_OVER_32_Q29 */ + + + + +/* -------------------------------- + normalization conversion tables + -------------------------------- */ + +static const Word32 SN3D_N3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, + SQRT_3_Q29, SQRT_3_Q29, SQRT_3_Q29, + SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, + SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29 }; + +static const Word32 N3D_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, + INV_SQRT_3_Q29, INV_SQRT_3_Q29, INV_SQRT_3_Q29, + INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, + INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29 }; + + +static const Word32 SN3D_MAXN[AMBI_MAX_CHANNELS] = { ONE_1_Q29, + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, + SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; + +static const Word32 MAXN_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, + INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; + +static const Word32 SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2_Q29, + ONE_1_Q29,ONE_1_Q29,ONE_1_Q29, + TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, + SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; + +static const Word32 FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_Q29, + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, + INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; + +/* ---------------------------- + 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 + ---------------------------------- */ + +/*-------------------------------------------------------------------------* +* convert_ambi_format() +* +* Convert signal between ACN-SN3D and other common ambisonics conventions +--------------------------------------------------------------------------*/ + +AMBI_CONVERT_ERROR convert_ambi_format( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 */ +) +{ + + Word32 tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; + Word32 *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; + + AMBI_CHANNEL_NORM ch_norm_in = AMBI_NORM_SN3D; + AMBI_CHANNEL_NORM 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 < AMBI_MAX_CHANNELS; j++ ) + { + p_tmp[j] = &tmp[j * L_FRAME48k]; + } + + switch ( in_format ) + { + 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_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; + break; + case AMBI_FMT_SID_N3D: + ch_ord_in = AMBI_CHANNEL_ORDER_SID; + ch_norm_in = AMBI_NORM_N3D; + break; + default: + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + + switch ( out_format ) + { + 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_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; + 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: + 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 ) + { + 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; + } + } + } + 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; + } + } + 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; + } + } + else + { + 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; + } + } + else if ( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) + { + int16_t i_chan = 0; + int16_t n_chan = i_mult2( add( order, 1), add( order, 1) ); + + 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 + { + assert( 0 && "This should never happen!" ); + } + + return AMBI_CONVERT_OK; +} + +/*-------------------------------------------------------------------------* +* renormalize_channels() +* +* Rescale audio channels according to the selected ambisonics convention +--------------------------------------------------------------------------*/ + +AMBI_CONVERT_ERROR renormalize_channels( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 = i_mult2( add( order, 1), add( order, 1) ); + int16_t i_chan, i; + const Word32 *conversion_table = 0; + + /* 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 ) + { + conversion_table = SN3D_N3D; + } + else if ( out_format == AMBI_NORM_MAXN ) + { + conversion_table = SN3D_MAXN; + } + else if ( out_format == AMBI_NORM_FM ) + { + conversion_table = SN3D_FM; + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + } + else if ( out_format == AMBI_NORM_SN3D ) + { + if ( in_format == AMBI_NORM_N3D ) + { + conversion_table = N3D_SN3D; + } + else if ( in_format == AMBI_NORM_MAXN ) + { + conversion_table = MAXN_SN3D; + } + else if ( in_format == AMBI_NORM_FM ) + { + conversion_table = FM_SN3D; + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + + + for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + { + Word32 conversion_factor = conversion_table[i_chan]; + for ( i = 0; i < L_FRAME48k; i++ ) + { + Word64 tmp; + tmp= W_mult0_32x32(in[i_chan][i], conversion_factor ); + tmp= W_shr(tmp, Q29 ); + out[i_chan][i] = W_extract_h( tmp ); + } + } + + return AMBI_CONVERT_OK; +} + +/*-------------------------------------------------------------------------* +* reorder_channels() +* +* Reorder channels according to the selected ambisonics convention +--------------------------------------------------------------------------*/ + +AMBI_CONVERT_ERROR reorder_channels( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 = i_mult2( add( order, 1), add( order, 1) ); + int16_t i_chan, i; + Word32 tmp[AMBI_MAX_CHANNELS]; + const int16_t *idx_table = 0; + + if ( in_format == AMBI_CHANNEL_ORDER_ACN ) + { + if ( out_format == AMBI_CHANNEL_ORDER_FM ) + { + idx_table = REORDER_ACN_FM; + } + else if ( out_format == AMBI_CHANNEL_ORDER_SID ) + { + idx_table = REORDER_ACN_SID; + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + } + else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) + { + if ( in_format == AMBI_CHANNEL_ORDER_FM ) + { + idx_table = REORDER_FM_ACN; + } + else if ( in_format == AMBI_CHANNEL_ORDER_SID ) + { + idx_table = REORDER_SID_ACN; + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + } + else + { + return AMBI_CONVERT_UNSUPPORTED_CONVERSION; + } + + 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 AMBI_CONVERT_OK; +} diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h new file mode 100644 index 000000000..d658c9a75 --- /dev/null +++ b/lib_util/ambi_convert.h @@ -0,0 +1,95 @@ +/****************************************************************************************************** + + (C) 2022-2025 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. + +*******************************************************************************************************/ + +#ifndef AMBI_CONVERT_H +#define AMBI_CONVERT_H + +#include + +#define L_FRAME48k 960 +#define AMBI_MAX_CHANNELS 16 + +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; + +typedef enum +{ + AMBI_NORM_SN3D = 0, + AMBI_NORM_N3D, + AMBI_NORM_MAXN, + AMBI_NORM_FM +} AMBI_CHANNEL_NORM; + +typedef enum +{ + AMBI_CHANNEL_ORDER_ACN = 0, + AMBI_CHANNEL_ORDER_FM, + AMBI_CHANNEL_ORDER_SID +} AMBI_CHANNEL_ORDER; + +typedef enum +{ + AMBI_CONVERT_OK = 0, + AMBI_CONVERT_UNSUPPORTED_CONVERSION +} AMBI_CONVERT_ERROR; + +AMBI_CONVERT_ERROR convert_ambi_format( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 */ +); + +AMBI_CONVERT_ERROR renormalize_channels( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 */ +); + +AMBI_CONVERT_ERROR reorder_channels( + Word32 *in[], /* i: input ambisonics channels */ + Word32 *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 c43527100d3844a38ee082fff6ec94fca300fb6e Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 29 Aug 2025 10:55:39 +0200 Subject: [PATCH 02/19] compiles. --- lib_util/ambi_convert.c | 84 ++++++++++++++++++++--------------------- lib_util/ambi_convert.h | 7 ++++ 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 05814651f..90fa692a4 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -34,31 +34,29 @@ #include #include "ambi_convert.h" -#define THISQ Q29 +#define THISQ Q29 -#define ONE_1_Q29 536870912l /* 1.0f */ +#define ONE_1_Q29 536870912l /* 1.0f */ -#define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ -#define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ -#define SQRT_5_Q29 1200479872l /* sqrtf(5.0f) */ -#define SQRT_7_Q29 1420426880l /* sqrtf(7.0f) */ +#define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ +#define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ +#define SQRT_5_Q29 1200479872l /* sqrtf(5.0f) */ +#define SQRT_7_Q29 1420426880l /* sqrtf(7.0f) */ -#define INV_SQRT_2_Q29 379625024l /* 1.0f/sqrtf(2.0f) */ -#define INV_SQRT_3_Q29 309962528l /* 1.0f/sqrtf(3.0f) */ -#define INV_SQRT_5_Q29 240095920l /* 1.0f/sqrtf(5.0f) */ -#define INV_SQRT_7_Q29 202918096l /* 1.0f/sqrtf(7.0f) */ - -#define TWO_OVER_SQRT_3_Q29 619925120l /* 2.0f/sqrtf(3.0f) */ -#define THREE_OVER_SQRT_5_Q29 720287936l /* 3.0f/sqrtf(5.0f) */ -#define SQRT_8_OVER_5_Q29 679093952l /* sqrtf(8.0f/5.0f) */ -#define SQRT_45_OVER_32_Q29 636650560l /* sqrtf(45.0f/32.0f) */ - -#define INV_TWO_OVER_SQRT_3_Q29 464943840l /* 1.0f/TWO_OVER_SQRT_3_Q29 */ -#define INV_THREE_OVER_SQRT_5_Q29 400159968l /* 1.0f/THREE_OVER_SQRT_5_Q29 */ -#define INV_SQRT_8_OVER_5_Q29 424433728l /* 1.0f/INV_SQRT_8_OVER_5_Q29 */ -#define INV_SQRT_45_OVER_32_Q29 452729280l /* 1.0f/SQRT_45_OVER_32_Q29 */ +#define INV_SQRT_2_Q29 379625024l /* 1.0f/sqrtf(2.0f) */ +#define INV_SQRT_3_Q29 309962528l /* 1.0f/sqrtf(3.0f) */ +#define INV_SQRT_5_Q29 240095920l /* 1.0f/sqrtf(5.0f) */ +#define INV_SQRT_7_Q29 202918096l /* 1.0f/sqrtf(7.0f) */ +#define TWO_OVER_SQRT_3_Q29 619925120l /* 2.0f/sqrtf(3.0f) */ +#define THREE_OVER_SQRT_5_Q29 720287936l /* 3.0f/sqrtf(5.0f) */ +#define SQRT_8_OVER_5_Q29 679093952l /* sqrtf(8.0f/5.0f) */ +#define SQRT_45_OVER_32_Q29 636650560l /* sqrtf(45.0f/32.0f) */ +#define INV_TWO_OVER_SQRT_3_Q29 464943840l /* 1.0f/TWO_OVER_SQRT_3_Q29 */ +#define INV_THREE_OVER_SQRT_5_Q29 400159968l /* 1.0f/THREE_OVER_SQRT_5_Q29 */ +#define INV_SQRT_8_OVER_5_Q29 424433728l /* 1.0f/INV_SQRT_8_OVER_5_Q29 */ +#define INV_SQRT_45_OVER_32_Q29 452729280l /* 1.0f/SQRT_45_OVER_32_Q29 */ /* -------------------------------- @@ -66,35 +64,35 @@ -------------------------------- */ static const Word32 SN3D_N3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, - SQRT_3_Q29, SQRT_3_Q29, SQRT_3_Q29, - SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, - SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29 }; + SQRT_3_Q29, SQRT_3_Q29, SQRT_3_Q29, + SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, + SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29 }; static const Word32 N3D_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, - INV_SQRT_3_Q29, INV_SQRT_3_Q29, INV_SQRT_3_Q29, - INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, - INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29 }; + INV_SQRT_3_Q29, INV_SQRT_3_Q29, INV_SQRT_3_Q29, + INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, + INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29 }; static const Word32 SN3D_MAXN[AMBI_MAX_CHANNELS] = { ONE_1_Q29, - ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, - TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, - SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, + SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; static const Word32 MAXN_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29, - ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, - INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, - INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, + INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; static const Word32 SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2_Q29, - ONE_1_Q29,ONE_1_Q29,ONE_1_Q29, - TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, - SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, + SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 }; static const Word32 FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_Q29, - ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, - INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, - INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; + ONE_1_Q29, ONE_1_Q29, ONE_1_Q29, + INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, + INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 }; /* ---------------------------- channel re-ordering tables @@ -280,7 +278,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( else if ( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) { int16_t i_chan = 0; - int16_t n_chan = i_mult2( add( order, 1), add( order, 1) ); + int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { @@ -313,7 +311,7 @@ AMBI_CONVERT_ERROR renormalize_channels( AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ) { - int16_t n_chan = i_mult2( add( order, 1), add( order, 1) ); + int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); int16_t i_chan, i; const Word32 *conversion_table = 0; @@ -368,8 +366,8 @@ AMBI_CONVERT_ERROR renormalize_channels( for ( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; - tmp= W_mult0_32x32(in[i_chan][i], conversion_factor ); - tmp= W_shr(tmp, Q29 ); + tmp = W_mult0_32_32( in[i_chan][i], conversion_factor ); + tmp = W_shr( tmp, Q29 ); out[i_chan][i] = W_extract_h( tmp ); } } @@ -391,7 +389,7 @@ AMBI_CONVERT_ERROR reorder_channels( AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ ) { - int16_t n_chan = i_mult2( add( order, 1), add( order, 1) ); + int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); int16_t i_chan, i; Word32 tmp[AMBI_MAX_CHANNELS]; const int16_t *idx_table = 0; diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index d658c9a75..2b1f4480a 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -34,6 +34,13 @@ #define AMBI_CONVERT_H #include +#include "options.h" +#include "prot_fx.h" +#include "ivas_cnst.h" +#include +#include "wmc_auto.h" +#include "ivas_prot_fx.h" + #define L_FRAME48k 960 #define AMBI_MAX_CHANNELS 16 -- GitLab From 2233467aaee4d7e0a98caa6c33ac311da0a7a71f Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 1 Sep 2025 12:31:31 +0200 Subject: [PATCH 03/19] typo in renormalize_channels() of ambi_convert.c caused wrong output. --- lib_util/ambi_convert.c | 2 +- scripts/compile_ambi_converter.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 scripts/compile_ambi_converter.sh diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 90fa692a4..53d0b2204 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -368,7 +368,7 @@ AMBI_CONVERT_ERROR renormalize_channels( Word64 tmp; tmp = W_mult0_32_32( in[i_chan][i], conversion_factor ); tmp = W_shr( tmp, Q29 ); - out[i_chan][i] = W_extract_h( tmp ); + out[i_chan][i] = W_extract_l( tmp ); } } diff --git a/scripts/compile_ambi_converter.sh b/scripts/compile_ambi_converter.sh new file mode 100644 index 000000000..39f084c29 --- /dev/null +++ b/scripts/compile_ambi_converter.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +rm -r ambi_converter +cc ambi_converter.c -o ambi_converter -I../lib_util/ -I../lib_com/ -I../lib_debug/ -I../lib_enc/ -I../lib_dec/ -I../lib_rend/ -I../lib_isar -I../lib_lc3plus -L../ -livasutil -lm -- GitLab From 93a87de3c3c87f9f1500dd6aa7e66ce81f2fb49b Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 2 Sep 2025 11:29:16 +0200 Subject: [PATCH 04/19] reduced the bitwidth fron 32 to 16 bit for the ambisonic converter. --- lib_util/ambi_convert.c | 27 ++++++++++++++------------- lib_util/ambi_convert.h | 12 ++++++------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 53d0b2204..aa6753659 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -34,9 +34,8 @@ #include #include "ambi_convert.h" -#define THISQ Q29 - #define ONE_1_Q29 536870912l /* 1.0f */ +#define ONE_OVER_2_Q29 268435456 /* 1.0f/2.0f */ #define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ #define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ @@ -129,16 +128,16 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR convert_ambi_format( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ ) { - Word32 tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; - Word32 *p_tmp[AMBI_MAX_CHANNELS]; + Word16 tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; + Word16 *p_tmp[AMBI_MAX_CHANNELS]; AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN; @@ -304,8 +303,8 @@ AMBI_CONVERT_ERROR convert_ambi_format( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR renormalize_channels( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ @@ -315,6 +314,7 @@ AMBI_CONVERT_ERROR renormalize_channels( int16_t i_chan, i; const Word32 *conversion_table = 0; + /* conversion factors are applied on the channels assuming that they are still/already in ACN order */ if ( in_format == AMBI_NORM_SN3D ) { @@ -366,9 +366,10 @@ AMBI_CONVERT_ERROR renormalize_channels( for ( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; - tmp = W_mult0_32_32( in[i_chan][i], conversion_factor ); + tmp = W_mult0_32_32( (Word32)in[i_chan][i], conversion_factor ); + /* tmp = W_add( tmp, ONE_OVER_2_Q29); */ /* rounding up */ tmp = W_shr( tmp, Q29 ); - out[i_chan][i] = W_extract_l( tmp ); + out[i_chan][i] = extract_l( W_extract_l( tmp ) ); } } @@ -382,8 +383,8 @@ AMBI_CONVERT_ERROR renormalize_channels( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR reorder_channels( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ @@ -391,7 +392,7 @@ AMBI_CONVERT_ERROR reorder_channels( { int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); int16_t i_chan, i; - Word32 tmp[AMBI_MAX_CHANNELS]; + Word16 tmp[AMBI_MAX_CHANNELS]; const int16_t *idx_table = 0; if ( in_format == AMBI_CHANNEL_ORDER_ACN ) diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 2b1f4480a..befdfc629 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -77,24 +77,24 @@ typedef enum } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ ); AMBI_CONVERT_ERROR renormalize_channels( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ ); AMBI_CONVERT_ERROR reorder_channels( - Word32 *in[], /* i: input ambisonics channels */ - Word32 *out[], /* o: output ambisonics channels */ + Word16 *in[], /* i: input ambisonics channels */ + Word16 *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 */ -- GitLab From bb274d8aa717f23c903f6c1ef61daa21baa9f38d Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 2 Sep 2025 11:39:15 +0200 Subject: [PATCH 05/19] applied the clang patch. --- lib_util/ambi_convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index aa6753659..ade8f8d5a 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -34,8 +34,8 @@ #include #include "ambi_convert.h" -#define ONE_1_Q29 536870912l /* 1.0f */ -#define ONE_OVER_2_Q29 268435456 /* 1.0f/2.0f */ +#define ONE_1_Q29 536870912l /* 1.0f */ +#define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */ #define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ #define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ @@ -366,7 +366,7 @@ AMBI_CONVERT_ERROR renormalize_channels( for ( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; - tmp = W_mult0_32_32( (Word32)in[i_chan][i], conversion_factor ); + tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); /* tmp = W_add( tmp, ONE_OVER_2_Q29); */ /* rounding up */ tmp = W_shr( tmp, Q29 ); out[i_chan][i] = extract_l( W_extract_l( tmp ) ); -- GitLab From c5078263d25e859922b0cb8a88cce65a1b83e287 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 2 Sep 2025 12:28:24 +0200 Subject: [PATCH 06/19] applied the clang patch. --- 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 ade8f8d5a..6dc525365 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -35,7 +35,7 @@ #include "ambi_convert.h" #define ONE_1_Q29 536870912l /* 1.0f */ -#define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */ +#define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */ #define SQRT_2_Q29 759250112l /* sqrtf(2.0f) */ #define SQRT_3_Q29 929887680l /* sqrtf(3.0f) */ -- GitLab From ed39cf696da659958fe4f53810ea7276ed5e0b5c Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 2 Sep 2025 12:47:23 +0200 Subject: [PATCH 07/19] applied the basop instrumentalisation. --- lib_util/ambi_convert.c | 145 ++++++++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 50 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 6dc525365..dfac4d957 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -146,149 +146,180 @@ AMBI_CONVERT_ERROR convert_ambi_format( AMBI_CHANNEL_NORM ch_norm_in = AMBI_NORM_SN3D; AMBI_CHANNEL_NORM ch_norm_out = AMBI_NORM_SN3D; + Word16 i,j; + 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 < AMBI_MAX_CHANNELS; j++ ) + i = 0; + move16(); + FOR( j = 0; j < AMBI_MAX_CHANNELS; j++ ) { - p_tmp[j] = &tmp[j * L_FRAME48k]; + p_tmp[j] = &tmp[i]; + move32(); + i = add( i, L_FRAME48k ); } - switch ( in_format ) + SWITCH( in_format ) { case AMBI_FMT_ACN_SN3D: ch_ord_in = AMBI_CHANNEL_ORDER_ACN; ch_norm_in = AMBI_NORM_SN3D; + move16(); + move16(); break; case AMBI_FMT_ACN_N3D: ch_ord_in = AMBI_CHANNEL_ORDER_ACN; ch_norm_in = AMBI_NORM_N3D; + move16(); + move16(); break; case AMBI_FMT_FM_MAXN: ch_ord_in = AMBI_CHANNEL_ORDER_FM; ch_norm_in = AMBI_NORM_MAXN; + move16(); + move16(); break; case AMBI_FMT_FM_FM: ch_ord_in = AMBI_CHANNEL_ORDER_FM; ch_norm_in = AMBI_NORM_FM; + move16(); + move16(); break; case AMBI_FMT_SID_SN3D: ch_ord_in = AMBI_CHANNEL_ORDER_SID; ch_norm_in = AMBI_NORM_SN3D; + move16(); + move16(); break; case AMBI_FMT_SID_N3D: ch_ord_in = AMBI_CHANNEL_ORDER_SID; ch_norm_in = AMBI_NORM_N3D; + move16(); + move16(); break; default: return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } - switch ( out_format ) + SWITCH( out_format ) { case AMBI_FMT_ACN_SN3D: ch_ord_out = AMBI_CHANNEL_ORDER_ACN; ch_norm_out = AMBI_NORM_SN3D; + move16(); + move16(); break; case AMBI_FMT_ACN_N3D: ch_ord_out = AMBI_CHANNEL_ORDER_ACN; ch_norm_out = AMBI_NORM_N3D; + move16(); + move16(); break; case AMBI_FMT_FM_MAXN: ch_ord_out = AMBI_CHANNEL_ORDER_FM; ch_norm_out = AMBI_NORM_MAXN; + move16(); + move16(); break; case AMBI_FMT_FM_FM: ch_ord_out = AMBI_CHANNEL_ORDER_FM; ch_norm_out = AMBI_NORM_FM; + move16(); + move16(); break; case AMBI_FMT_SID_SN3D: ch_ord_out = AMBI_CHANNEL_ORDER_SID; ch_norm_out = AMBI_NORM_SN3D; + move16(); + move16(); break; case AMBI_FMT_SID_N3D: ch_ord_out = AMBI_CHANNEL_ORDER_SID; ch_norm_out = AMBI_NORM_N3D; + move16(); + move16(); break; default: return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } - if ( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) + IF( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { - if ( ch_ord_in != ch_ord_out ) + IF( ch_ord_in != ch_ord_out ) { - if ( ( err = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + 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 ) + IF( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { return err; } } - else + 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; } } } - else if ( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) + 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 ) + 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 ) + ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { - if ( ch_ord_in != ch_ord_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 ) + 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 ) + IF( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) { return err; } } - else + 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; } } } - else if ( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) + 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 ) + 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 ) + ELSE IF( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) { int16_t i_chan = 0; int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { int16_t i = 0; - for ( i = 0; i < L_FRAME48k; i++ ) + move16(); + FOR( i = 0; i < L_FRAME48k; i++ ) { out[i_chan][i] = in[i_chan][i]; + move16(); } } } - else + ELSE { assert( 0 && "This should never happen!" ); } @@ -316,54 +347,61 @@ AMBI_CONVERT_ERROR renormalize_channels( /* conversion factors are applied 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 ) + IF( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; + move32(); } - else if ( out_format == AMBI_NORM_MAXN ) + ELSE IF( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; + move32(); } - else if ( out_format == AMBI_NORM_FM ) + ELSE IF( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; + move32(); } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } - else if ( out_format == AMBI_NORM_SN3D ) + ELSE IF( out_format == AMBI_NORM_SN3D ) { - if ( in_format == AMBI_NORM_N3D ) + IF( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; + move32(); } - else if ( in_format == AMBI_NORM_MAXN ) + ELSE IF( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; + move32(); } - else if ( in_format == AMBI_NORM_FM ) + ELSE IF( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; + move32(); } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { Word32 conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) + move32(); + FOR( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); @@ -395,51 +433,58 @@ AMBI_CONVERT_ERROR reorder_channels( Word16 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 ) + IF( out_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_ACN_FM; + move16(); } - else if ( out_format == AMBI_CHANNEL_ORDER_SID ) + ELSE IF( out_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_ACN_SID; + move16(); } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } - else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) + ELSE IF( out_format == AMBI_CHANNEL_ORDER_ACN ) { - if ( in_format == AMBI_CHANNEL_ORDER_FM ) + IF( in_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_FM_ACN; + move16(); } - else if ( in_format == AMBI_CHANNEL_ORDER_SID ) + ELSE IF( in_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_SID_ACN; + move16(); } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } - else + ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } - for ( i = 0; i < L_FRAME48k; i++ ) + FOR( i = 0; i < L_FRAME48k; i++ ) { - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { int16_t idx = idx_table[i_chan]; + move16(); tmp[i_chan] = in[idx][i]; + move16(); } - for ( i_chan = 0; i_chan < n_chan; i_chan++ ) + FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { out[i_chan][i] = tmp[i_chan]; + move16(); } } -- GitLab From dee64c132beb46caf36201988c4214732720ac47 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 2 Sep 2025 12:52:39 +0200 Subject: [PATCH 08/19] applied the clang patch. --- 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 dfac4d957..fa1cfa4f6 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -146,7 +146,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( AMBI_CHANNEL_NORM ch_norm_in = AMBI_NORM_SN3D; AMBI_CHANNEL_NORM ch_norm_out = AMBI_NORM_SN3D; - Word16 i,j; + Word16 i, j; assert( order <= 3 ); -- GitLab From 8950f44aeebecfa81fc58a9cd6039cc9e4b0ece9 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 3 Sep 2025 11:18:11 +0200 Subject: [PATCH 09/19] the ambi convert function reports a AMBI_CONVERT_CLIPPING_DETECTED error in case the output does no longer fit into 16 bit. --- lib_util/ambi_convert.c | 18 +++++++++++++++--- lib_util/ambi_convert.h | 3 ++- scripts/compile_ambi_converter.sh | 4 ---- 3 files changed, 17 insertions(+), 8 deletions(-) delete mode 100644 scripts/compile_ambi_converter.sh diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index fa1cfa4f6..6846a9270 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -32,6 +32,7 @@ #include #include +#include "wmc_auto.h" #include "ambi_convert.h" #define ONE_1_Q29 536870912l /* 1.0f */ @@ -344,6 +345,11 @@ AMBI_CONVERT_ERROR renormalize_channels( int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); int16_t i_chan, i; const Word32 *conversion_table = 0; + Word32 minval = 0; + Word32 maxval = 0; + move32(); + move32(); + move32(); /* conversion factors are applied on the channels assuming that they are still/already in ACN order */ @@ -400,17 +406,23 @@ AMBI_CONVERT_ERROR renormalize_channels( FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { Word32 conversion_factor = conversion_table[i_chan]; + Word32 outval; move32(); FOR( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); /* tmp = W_add( tmp, ONE_OVER_2_Q29); */ /* rounding up */ - tmp = W_shr( tmp, Q29 ); - out[i_chan][i] = extract_l( W_extract_l( tmp ) ); + outval = W_extract_l( W_shr( tmp, Q29 ) ); + minval = L_min( minval, outval ); + maxval = L_min( maxval, outval ); + out[i_chan][i] = extract_l( outval ); } } - + IF( ( minval < MIN16B ) || ( maxval > MAX16B ) ) + { + return AMBI_CONVERT_CLIPPING_DETECTED; + } return AMBI_CONVERT_OK; } diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index befdfc629..a6e7cb1ae 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -73,7 +73,8 @@ typedef enum typedef enum { AMBI_CONVERT_OK = 0, - AMBI_CONVERT_UNSUPPORTED_CONVERSION + AMBI_CONVERT_UNSUPPORTED_CONVERSION, + AMBI_CONVERT_CLIPPING_DETECTED } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( diff --git a/scripts/compile_ambi_converter.sh b/scripts/compile_ambi_converter.sh deleted file mode 100644 index 39f084c29..000000000 --- a/scripts/compile_ambi_converter.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -rm -r ambi_converter -cc ambi_converter.c -o ambi_converter -I../lib_util/ -I../lib_com/ -I../lib_debug/ -I../lib_enc/ -I../lib_dec/ -I../lib_rend/ -I../lib_isar -I../lib_lc3plus -L../ -livasutil -lm -- GitLab From ca21bc6655f71a26c9c05186f9b1d73a8564867f Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 3 Sep 2025 14:16:12 +0200 Subject: [PATCH 10/19] documented the format of the input and output samples for the ambi_converter as Q0 in the comments. --- lib_util/ambi_convert.c | 30 +++++++++++++++--------------- lib_util/ambi_convert.h | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 6846a9270..0bf2bf226 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -129,11 +129,11 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR convert_ambi_format( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ ) { @@ -335,11 +335,11 @@ AMBI_CONVERT_ERROR convert_ambi_format( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR renormalize_channels( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + 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 = i_mult2( add( order, 1 ), add( order, 1 ) ); @@ -433,11 +433,11 @@ AMBI_CONVERT_ERROR renormalize_channels( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR reorder_channels( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + 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 = i_mult2( add( order, 1 ), add( order, 1 ) ); diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index a6e7cb1ae..207bd276f 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -78,26 +78,26 @@ typedef enum } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + int16_t order, /* i: ambisonics order */ + AMBI_FMT in_format, /* i: input ambisonics format */ + AMBI_FMT out_format /* i: output ambisonics format */ ); AMBI_CONVERT_ERROR renormalize_channels( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + int16_t order, /* i: ambisonics order */ + AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); AMBI_CONVERT_ERROR reorder_channels( - Word16 *in[], /* i: input ambisonics channels */ - Word16 *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 */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + 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 f5694d88213267d5b97da9367940eb7ccba078d9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 19 Sep 2025 17:43:14 +0200 Subject: [PATCH 11/19] updates from MR 212, 236, 254 --- apps/decoder.c | 49 +++---- apps/renderer.c | 4 + lib_com/common_api_types.h | 7 +- lib_com/ivas_prot_fx.h | 36 +++++- lib_com/options.h | 1 + lib_dec/ivas_binRenderer_internal_fx.c | 17 ++- lib_dec/ivas_init_dec_fx.c | 49 ++++++- lib_dec/ivas_ism_dec_fx.c | 73 ++++++++--- lib_dec/ivas_masa_dec_fx.c | 42 +++--- lib_dec/ivas_mct_dec_fx.c | 55 ++++++-- lib_dec/ivas_objectRenderer_internal_fx.c | 9 ++ lib_dec/ivas_omasa_dec_fx.c | 11 +- lib_dec/ivas_sba_dec_fx.c | 23 +++- lib_dec/lib_dec_fx.c | 122 ++++++++++++++++-- lib_isar/lib_isar_post_rend.c | 4 + lib_rend/ivas_crend_fx.c | 1 + .../ivas_dirac_dec_binaural_functions_fx.c | 12 +- lib_rend/ivas_dirac_rend_fx.c | 2 +- lib_rend/ivas_hrtf_fx.c | 82 ++---------- lib_rend/ivas_objectRenderer_sources_fx.c | 4 +- lib_rend/ivas_prot_rend_fx.h | 18 +-- lib_rend/ivas_render_config_fx.c | 4 + lib_rend/ivas_rom_binauralRenderer.h | 53 ++++---- lib_rend/ivas_rom_binauralRenderer_fx.c | 4 +- lib_rend/ivas_rom_binaural_crend_head.h | 52 ++++---- lib_rend/ivas_rom_binaural_crend_head_fx.c | 5 +- lib_rend/ivas_stat_rend.h | 1 + lib_rend/lib_rend_fx.c | 40 ++++-- lib_util/hrtf_file_reader.c | 21 ++- lib_util/render_config_reader.c | 16 +++ 30 files changed, 547 insertions(+), 270 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b914b3ae4..133bc23e9 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2221,23 +2221,23 @@ static ivas_error decodeG192( } #ifdef FIX_CREND_SIMPLIFY_CODE - /* Load HRTF binary file data */ - if ( arg.hrtfReaderEnabled ) + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer; + hHrtfBinary->binaural_renderer_sec_old = hHrtfBinary->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) { - /* Read main parameters from the bitstream to set-up the decoder */ - hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer; - hHrtfBinary->binaural_renderer_sec_old = hHrtfBinary->binaural_renderer_sec; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; + } - /* Placeholder for memory reallocation */ - /* ... */ + /* Placeholder for memory reallocation */ + /* ... */ + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { if ( ( error = load_hrtf_from_file( hHrtfBinary, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nload_hrtf_from_file failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } } @@ -2993,23 +2993,23 @@ static ivas_error decodeVoIP( #ifdef FIX_CREND_SIMPLIFY_CODE if ( bitstreamReadDone == true ) { - /* Load HRTF binary file data */ - if ( arg.hrtfReaderEnabled ) + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) { - /* Read main parameters from the bitstream to set-up the decoder */ - hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; + } - /* Placeholder for memory reallocation */ - /* ... */ + /* Placeholder for memory reallocation */ + /* ... */ + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + fprintf( stderr, "\nload_hrtf_from_file failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } } @@ -3299,6 +3299,7 @@ cleanup: return error; } + #ifdef FIX_CREND_SIMPLIFY_CODE /*---------------------------------------------------------------------* * load_hrtf_from_file() diff --git a/apps/renderer.c b/apps/renderer.c index c84cbac9e..97de60532 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -693,7 +693,11 @@ static int16_t get_cldfb_in_flag( int16_t cldfb_in_flag; cldfb_in_flag = 0; +#ifdef FIX_HRTF_LOAD + if ( renderConfig->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( renderConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { #ifdef DEBUGGING cldfb_in_flag = 1; diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 099239536..cdbae021b 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -274,6 +274,7 @@ typedef enum } ISAR_SPLIT_REND_CODEC; +#ifndef FIX_HRTF_LOAD typedef enum { ISAR_SPLIT_REND_RENDERER_SELECTION_CREND, @@ -283,7 +284,7 @@ typedef enum ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT, } ISAR_SPLIT_REND_RENDERER_SELECTION; - +#endif typedef struct _ISAR_SPLIT_REND_BITS_DATA { uint8_t *bits_buf; @@ -314,7 +315,11 @@ typedef struct _ISAR_SPLIT_REND_CONFIG int16_t codec_frame_size_ms; /* Codec frame size in milliseconds, only relevant with LC3plus */ ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrectionMode; ISAR_SPLIT_REND_CODEC codec; +#ifdef FIX_HRTF_LOAD + IVAS_BIN_RENDERER_TYPE rendererSelection; +#else ISAR_SPLIT_REND_RENDERER_SELECTION rendererSelection; +#endif int16_t lc3plus_highres; } ISAR_SPLIT_REND_CONFIG_DATA, *ISAR_SPLIT_REND_CONFIG_HANDLE; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ccfc4fe0d..87dce6d2f 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -114,9 +114,12 @@ void ivas_masa_prerender_fx( ); ivas_error ivas_masa_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ); void reconstruct_ism_ratios_fx( @@ -192,10 +195,15 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( ivas_error ivas_omasa_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef FIX_HRTF_LOAD + Word16 *num_src, + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS] +#else UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], Word16 *data /* o : output synthesis signal */ +#endif ); void ivas_omasa_modify_masa_energy_ratios_fx( @@ -2363,9 +2371,12 @@ void ivas_destroy_dec_fx( ivas_error ivas_ism_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ + const ISM_MODE last_ism_mode /* i/o: last ISM mode */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ Word16 *data /* o : output synthesis signal */ +#endif ); ivas_error ivas_ism_metadata_dec_create_fx( @@ -2379,9 +2390,12 @@ void ivas_ism_reset_metadata_handle_dec_fx( ); ivas_error ivas_sba_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesFlushed, /* o : number of samples flushed */ Word16 *data /* o : output synthesis signal */ +#endif ); ivas_error ivas_spar_md_dec_matrix_open_fx( @@ -2389,6 +2403,7 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( const Word16 num_channels, /* i : number of internal channels */ const Word16 num_md_sub_frames /* i : number of MD subframes */ ); + void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ const Word16 num_channels /* i : number of internal channels */ @@ -2416,9 +2431,12 @@ void ivas_omasa_data_close_fx( ivas_error ivas_mc_dec_config_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 idx, /* i : LS config. index */ + const Word16 idx /* i : LS config. index */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ); void ivas_lfe_window_init_fx( @@ -4034,9 +4052,12 @@ ivas_error ivas_dec_get_format_fx( ); ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ); ivas_error create_mct_dec_fx( @@ -4271,9 +4292,12 @@ ivas_error ivas_ism_metadata_enc_fx( ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ + const ISM_MODE last_ism_mode /* i/o: last ISM mode */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ Word16 *data /* o : output synthesis signal */ +#endif ); ivas_error ivas_param_ism_dec_open_fx( diff --git a/lib_com/options.h b/lib_com/options.h index e83a0613e..89d05dad3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -124,6 +124,7 @@ #define USE_REVERB_16BIT_ROM /* if desactivated old rom hrtf tables is used */ #define USE_TDREND_16BIT_ROM /* if desactivated old rom hrtf tables is used. when active some tests case with 4 ISM fail due to owerflow in round_fixed function */ #define USE_FASTCONV_PARAMBIN_16BIT_ROM /* if desactivated old rom hrtf tables is used */ +#define FIX_HRTF_LOAD /* VA: issue 1187: fix memory issue when HRTFs are loaded from a binary file */ #endif #define NONBE_1377_REND_DIRATT_CONF /* Eri: Issue 1377: Error in directivity attenuation configuration for both IVAS_dec and IVAS_rend */ #define FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK /* Eri: Issue 1999: Range check on float values of distance attenuation, while the float values are not propagated to this function. The test is not correct, but configurable distance attenuation is not used in Characterization.*/ diff --git a/lib_dec/ivas_binRenderer_internal_fx.c b/lib_dec/ivas_binRenderer_internal_fx.c index b8588a046..4691523c6 100644 --- a/lib_dec/ivas_binRenderer_internal_fx.c +++ b/lib_dec/ivas_binRenderer_internal_fx.c @@ -843,10 +843,11 @@ ivas_error ivas_allocate_binaural_hrtf_fx( } /*-------------------------------------------------------------------------* - * ivas_binaural_HRTF_open() + * ivas_binaural_hrtf_open() * * *-------------------------------------------------------------------------*/ + static ivas_error ivas_binaural_hrtf_open_fx( HRTFS_FASTCONV_HANDLE *hHrtfFastConv, /* i : fastconv HRTF handle */ const AUDIO_CONFIG input_config, /* i : output configuration */ @@ -1157,15 +1158,18 @@ static ivas_error ivas_binaural_hrtf_open_fx( #endif *hHrtfFastConv = HrtfFastConv; - } - return IVAS_ERR_OK; + return IVAS_ERR_OK; + } } + + /*-------------------------------------------------------------------------* - * ivas_binaural_obtain_DMX_fx() + * ivas_binaural_obtain_DMX() * * *-------------------------------------------------------------------------*/ + static void ivas_binaural_obtain_DMX_fx( const Word16 numTimeSlots, BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */ @@ -1484,8 +1488,10 @@ ivas_error ivas_binRenderer_open_fx( /* Define of head rotation has to be done in binRendeder in CLDFB*/ hBinRenderer->rotInCldfb = 0; move16(); + test(); - if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { hBinRenderer->rotInCldfb = 1; move16(); @@ -1552,6 +1558,7 @@ ivas_error ivas_binRenderer_open_fx( return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in FastConv renderer" ); } #endif + /* Load HRTF tables */ IF( NE_32( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 580ba9d06..6fbd4f28b 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -524,9 +524,12 @@ ivas_error ivas_dec_get_format_fx( *-------------------------------------------------------------------*/ ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ) { Word16 k, idx, num_bits_read; @@ -595,7 +598,11 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = nchan_ism; move16(); +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, st_ivas->ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -618,7 +625,11 @@ ivas_error ivas_dec_setup( test(); IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -695,7 +706,11 @@ ivas_error ivas_dec_setup( } ELSE { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -703,7 +718,11 @@ ivas_error ivas_dec_setup( } ELSE { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, &num_src, SrcInd ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -729,7 +748,11 @@ ivas_error ivas_dec_setup( test(); IF( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || ( st_ivas->ini_active_frame == 0 ) ) { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, &num_src, SrcInd ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_omasa_dec_config_fx( st_ivas, nSamplesRendered, &num_src, SrcInd, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -768,7 +791,11 @@ ivas_error ivas_dec_setup( test(); IF( st_ivas->ini_frame > 0 && NE_32( ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ) { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -818,7 +845,11 @@ ivas_error ivas_dec_setup( num_bits_read = add( num_bits_read, MC_LS_SETUP_BITS ); /* select MC format mode; reconfigure the MC format decoder */ +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_mc_dec_config_fx( st_ivas, idx ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_mc_dec_config_fx( st_ivas, idx, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -929,7 +960,11 @@ ivas_error ivas_dec_setup( move16(); } +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -988,7 +1023,11 @@ ivas_error ivas_dec_setup( move32(); } +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_ism_dec_config_fx( st_ivas, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -1146,12 +1185,13 @@ static ivas_error ivas_read_format( { st_ivas->ivas_format = SBA_ISM_FORMAT; move32(); + #ifdef FIX_CREND_SIMPLIFY_CODE /* read the real Ambisonic order when the above bits are used to signal OSBA format */ IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) { - st_ivas->sba_order = st_ivas->bit_stream[*num_bits_read + 2 + SBA_PLANAR_BITS + SBA_ORDER_BITS]; - st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[*num_bits_read + 1 + SBA_PLANAR_BITS + SBA_ORDER_BITS], 1 ) ); + st_ivas->sba_order = st_ivas->bit_stream[add( *num_bits_read, 2 + SBA_PLANAR_BITS + SBA_ORDER_BITS )]; + st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[add( *num_bits_read, 1 + SBA_PLANAR_BITS + SBA_ORDER_BITS )], 1 ) ); } #endif } @@ -1435,10 +1475,11 @@ ivas_error ivas_init_decoder_front( } } +#ifndef FIX_CREND_SIMPLIFY_CODE /*-------------------------------------------------------------------* * Allocate HRTF binary handle *--------------------------------------------------------------------*/ -#ifndef FIX_CREND_SIMPLIFY_CODE + IF( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { IF( NE_32( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ), IVAS_ERR_OK ) ) diff --git a/lib_dec/ivas_ism_dec_fx.c b/lib_dec/ivas_ism_dec_fx.c index 08d2c3401..4d5aeecff 100644 --- a/lib_dec/ivas_ism_dec_fx.c +++ b/lib_dec/ivas_ism_dec_fx.c @@ -48,9 +48,12 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nchan_transport_old, /* i : last number of transport channels */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples rendered */ - Word16 *data /* o : output synthesis signal Q0*/ + const ISM_MODE last_ism_mode /* i : last ISM mode */ +#ifndef FIX_HRTF_LOAD + , + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + Word16 *data /* o : output synthesis signal Q0*/ +#endif ) { ivas_error error; @@ -62,12 +65,16 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( Word16 tc_nchan_allocate_new; Word16 tc_granularity_new; Word16 nchan_out_buff, nchan_out_buff_old; +#ifndef FIX_HRTF_LOAD AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; +#endif +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; move32(); +#endif nCPE_old = st_ivas->nCPE; move16(); nSCE_old = st_ivas->nSCE; @@ -109,11 +116,14 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_transport_old ) ), IVAS_ERR_OK ) ) { return error; } + +#ifndef FIX_HRTF_LOAD /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; move32(); @@ -123,7 +133,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( move16(); renderer_type_old = st_ivas->renderer_type; move32(); - +#endif /*-----------------------------------------------------------------* * Initialize the needed renderer struct and destroy the unnecessary renderer struct *-----------------------------------------------------------------*/ @@ -161,15 +171,18 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) - { - IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) - { + IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ){ +#ifdef FIX_HRTF_LOAD + /* flush already done in IVAS_DEC_ReadFormat() */ +#else + IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ){ return error; - } + } +#endif } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + ELSE + IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { @@ -238,7 +251,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( #ifdef FIX_CREND_SIMPLIFY_CODE IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hHrtfCrend, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, 0, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ), IVAS_ERR_OK ) ) #else - IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ), IVAS_ERR_OK ) ) #endif st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; @@ -301,7 +314,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( #ifdef FIX_CREND_SIMPLIFY_CODE ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); #else - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); #endif } } @@ -382,9 +395,14 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( } } - return error; +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else +return error; +#endif } + /*------------------------------------------------------------------------- * ivas_ism_dec_config() * @@ -393,18 +411,23 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( *-------------------------------------------------------------------------*/ ivas_error ivas_ism_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - Word16 *data /* o : output synthesis signal Q0*/ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const ISM_MODE last_ism_mode /* i/o: last ISM mode */ +#ifndef FIX_HRTF_LOAD + , + UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ + Word16 *data /* o : output synthesis signal Q0*/ +#endif ) { Word32 ivas_total_brate; ivas_error error; Word16 nchan_transport_old; +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; move32(); +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); /* Assumes that num of input objects are constant */ @@ -443,9 +466,14 @@ ivas_error ivas_ism_dec_config_fx( { /* ISM bit-rate switching */ test(); - IF( ( NE_16( st_ivas->ism_mode, last_ism_mode ) ) || ( NE_32( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) + IF( ( NE_16( st_ivas->ism_mode, last_ism_mode ) ) || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) { +#ifdef FIX_HRTF_LOAD + IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode ) ), IVAS_ERR_OK ) ) + +#else IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -470,7 +498,11 @@ ivas_error ivas_ism_dec_config_fx( /* ISM mode switching */ IF( NE_32( st_ivas->ism_mode, last_ism_mode ) ) { +#ifdef FIX_HRTF_LOAD + IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode ) ), IVAS_ERR_OK ) ) +#else IF( NE_16( ( error = ivas_ism_bitrate_switching_dec_fx( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -500,5 +532,10 @@ ivas_error ivas_ism_dec_config_fx( move32(); BREAK; } + +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index 5980879b4..4851822db 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -188,9 +188,9 @@ ivas_error ivas_masa_decode_fx( { /* re-read the number of objects, needed in case of bad frame */ #ifdef FIX_CREND_SIMPLIFY_CODE - ch = sub( 5, add( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3], shl( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2], 1 ) ) ); + ch = sub( 5, add( st_ivas->bit_stream[sub( bits_per_frame, 3 )], shl( st_ivas->bit_stream[sub( bits_per_frame, 2 )], 1 ) ) ); - IF( EQ_16( ch, 5 ) ) + if ( EQ_16( ch, 5 ) ) { ch = 0; move16(); @@ -1677,16 +1677,13 @@ static Word16 decode_lfe_to_total_energy_ratio_fx( * Reconfigure IVAS MASA decoder *-------------------------------------------------------------------*/ -/*-------------------------------------------------------------------* - * ivas_masa_dec_reconfigure_fx() - * - * Reconfigure IVAS MASA decoder - *-------------------------------------------------------------------*/ - ivas_error ivas_masa_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ) { Word16 n, tmp, num_bits; @@ -1699,9 +1696,10 @@ ivas_error ivas_masa_dec_reconfigure_fx( Word32 ism_total_brate; Word16 pos_idx; +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; move16(); - +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; @@ -1741,7 +1739,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] == NULL ) ) { /* init a new DirAC dec */ - if ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -1793,7 +1791,6 @@ ivas_error ivas_masa_dec_reconfigure_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - // st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->element_brate = L_deposit_h( BASOP_Util_Divide3216_Scale( ivas_total_brate, st_ivas->nchan_transport, &tmp_e ) ); st_ivas->hSCE[sce_id]->element_brate = L_shr( st_ivas->hSCE[sce_id]->element_brate, sub( 15, tmp_e ) ); // Q0 @@ -1815,7 +1812,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] != NULL ) { - if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -1879,7 +1876,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] != NULL ) ) { - if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -1897,7 +1894,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] != NULL ) ) { - if ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { return error; } @@ -1921,6 +1918,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ + IF( st_ivas->hDiracDecBin[0] != NULL ) { IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ), IVAS_ERR_OK ) ) @@ -1932,6 +1930,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ + IF( st_ivas->hSpar ) { Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 ); @@ -1939,7 +1938,8 @@ ivas_error ivas_masa_dec_reconfigure_fx( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp; move16(); } - if ( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) + + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -2017,7 +2017,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( n_samples_granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ IF( GT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { - if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -2027,10 +2027,14 @@ ivas_error ivas_masa_dec_reconfigure_fx( { IF( LT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { +#ifdef FIX_HRTF_LOAD + /* flush already done in IVAS_DEC_ReadFormat() */ +#else if ( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } +#endif } } } @@ -2077,7 +2081,11 @@ ivas_error ivas_masa_dec_reconfigure_fx( } } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index d66a373e8..c8f23adc6 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -48,7 +48,11 @@ * Local function prototypes *-----------------------------------------------------------------------*/ +#ifdef FIX_HRTF_LOAD +static ivas_error ivas_mc_dec_reconfig_fx( Decoder_Struct *st_ivas ); +#else static ivas_error ivas_mc_dec_reconfig_fx( Decoder_Struct *st_ivas, UWord16 *nSamplesRendered, Word16 *data ); +#endif /*--------------------------------------------------------------------------* @@ -816,10 +820,13 @@ void ivas_mct_dec_close( /*! r : MC format mode */ ivas_error ivas_mc_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 idx, /* i : LS config. index */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 idx /* i : LS config. index */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ) { AUDIO_CONFIG signaled_config; @@ -859,10 +866,16 @@ ivas_error ivas_mc_dec_config_fx( move16(); } } + +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_mc_dec_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } + IF( st_ivas->hRenderConfig ) { FOR( Word16 i = 0; i < 4; i++ ) @@ -889,9 +902,12 @@ ivas_error ivas_mc_dec_config_fx( *-------------------------------------------------------------------------*/ static ivas_error ivas_mc_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ Word16 *data /* o : output synthesis signal */ +#endif ) { Word16 nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; @@ -905,12 +921,17 @@ static ivas_error ivas_mc_dec_reconfig_fx( Word16 tc_nchan_tc_new; Word16 tc_nchan_allocate_new; Word16 tc_granularity_new; +#ifndef FIX_HRTF_LOAD AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; +#endif Word16 nchan_out_buff_old, nchan_out_buff; + +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; move32(); +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); nchan_transport_old = st_ivas->nchan_transport; @@ -949,13 +970,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); move16(); +#ifndef FIX_HRTF_LOAD /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; move32(); hIntSetupOld = st_ivas->hIntSetup; tc_granularity_new = 1; move16(); - +#endif /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; move32(); @@ -999,12 +1021,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); move16(); - IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) - { - IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) - { + IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ){ +#ifdef FIX_HRTF_LOAD + /* flush already done in IVAS_DEC_ReadFormat() */ +#else + IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ), IVAS_ERR_OK ) ){ return error; - } +} +#endif } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) @@ -1370,7 +1394,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( #ifdef NONBE_FIX_1220_OMASA_JBM_EXT_USAN ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) #else - ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->hDirAC != NULL ) + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->hDirAC != NULL ) #endif { ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); @@ -1421,7 +1445,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( #ifdef FIX_CREND_SIMPLIFY_CODE ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); #else - ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); + ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ), ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ); #endif } @@ -1490,7 +1514,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( #ifdef FIX_CREND_SIMPLIFY_CODE IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hHrtfCrend, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, 0, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) #else - IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hHrtfStatistics, st_ivas->hDecoderConfig->output_Fs, ( st_ivas->hSplitBinRend == NULL ) ? 1 : st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses ) ) != IVAS_ERR_OK ) #endif { return error; @@ -1671,5 +1695,10 @@ static ivas_error ivas_mc_dec_reconfig_fx( { return error; } - return error; + +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else +return error; +#endif } diff --git a/lib_dec/ivas_objectRenderer_internal_fx.c b/lib_dec/ivas_objectRenderer_internal_fx.c index 914dde94e..5e898d236 100644 --- a/lib_dec/ivas_objectRenderer_internal_fx.c +++ b/lib_dec/ivas_objectRenderer_internal_fx.c @@ -62,6 +62,15 @@ ivas_error ivas_td_binaural_open_fx( move16(); } +#ifdef FIX_HRTF_LOAD + if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary && + ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 + ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); + } + +#endif return ivas_td_binaural_open_unwrap_fx( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, *num_src, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity_fx, st_ivas->hRenderConfig->distAtt_fx, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns, SrcInd ); } diff --git a/lib_dec/ivas_omasa_dec_fx.c b/lib_dec/ivas_omasa_dec_fx.c index 439958731..7278b9968 100644 --- a/lib_dec/ivas_omasa_dec_fx.c +++ b/lib_dec/ivas_omasa_dec_fx.c @@ -467,11 +467,16 @@ void ivas_omasa_data_close_fx( *--------------------------------------------------------------------------*/ ivas_error ivas_omasa_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ +#ifdef FIX_HRTF_LOAD + Word16 *num_src, + Word16 SrcInd[MAX_NUM_TDREND_CHANNELS] +#else UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], Word16 *data /* o : output synthesis signal Qx*/ +#endif ) { Word16 k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -535,7 +540,11 @@ ivas_error ivas_omasa_dec_config_fx( } ELSE { +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_masa_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } diff --git a/lib_dec/ivas_sba_dec_fx.c b/lib_dec/ivas_sba_dec_fx.c index c5df63529..6a77c5c0e 100644 --- a/lib_dec/ivas_sba_dec_fx.c +++ b/lib_dec/ivas_sba_dec_fx.c @@ -107,9 +107,12 @@ void ivas_sba_set_cna_cng_flag( *-------------------------------------------------------------------*/ ivas_error ivas_sba_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD + , UWord16 *nSamplesFlushed, /* o : number of samples flushed Q0*/ Word16 *data /* o : output synthesis signal Q0*/ +#endif ) { Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; @@ -176,8 +179,10 @@ ivas_error ivas_sba_dec_reconfigure_fx( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); +#ifndef FIX_HRTF_LOAD *nSamplesFlushed = 0; move16(); +#endif granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /*Q0*/ move16(); @@ -236,6 +241,9 @@ ivas_error ivas_sba_dec_reconfigure_fx( /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { +#ifdef FIX_HRTF_LOAD + /* flush already done in IVAS_DEC_ReadFormat() */ +#else /* write back info for correct rendering of the flushable samples */ st_ivas->sba_analysis_order = sba_analysis_order_old_flush; /*Q0*/ move16(); @@ -252,6 +260,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( move16(); st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; /*Q0*/ move32(); +#endif } ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { @@ -621,6 +630,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) ) { return error; @@ -641,6 +651,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; @@ -763,10 +774,20 @@ ivas_error ivas_sba_dec_reconfigure_fx( return error; } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } +/*-------------------------------------------------------------------* + * ivas_sba_dec_digest_tc() + * + * + *-------------------------------------------------------------------*/ + void ivas_sba_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 nCldfbSlots, /* i : number of CLDFB slots Q0*/ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index a6e5a5595..58396d862 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -96,6 +96,12 @@ struct IVAS_DEC Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 prev_ft_speech; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ Word16 CNG; /* RXDTX handler: CNG=1, nonCNG=0 */ + +#ifdef FIX_HRTF_LOAD + UWord16 nSamplesFlushed; + Word16 *flushbuffer; + bool hasBeenPreparedRendering; +#endif }; /*---------------------------------------------------------------------* @@ -110,7 +116,11 @@ static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSam static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts ); +#ifdef FIX_HRTF_LOAD +static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels ); +#else static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels, UWord8 *nOutChannels, UWord16 *nSamplesRendered, Word16 *data ); +#endif static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf ); static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf ); @@ -1158,10 +1168,14 @@ ivas_error IVAS_DEC_GetSamples( /* check if we need to run the setup function */ test(); IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){ - /* setup */ - - IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){ - return error; + /* setup */ +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels ) ), IVAS_ERR_OK ) ) +#else + IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ) +#endif + { + return error; } } { @@ -1558,30 +1572,40 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 *nTcBufferGranularity, /* o : granularity of the TC Buffer */ - UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ - UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ - UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */ - Word16 *data /* o : output synthesis signal Q0 */ + UWord8 *nTransportChannels /* o : number of decoded transport PCM channels */ +#ifndef FIX_HRTF_LOAD + , + UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */ + Word16 *data /* o : output synthesis signal Q0 */ +#endif ) { ivas_error error; +#ifndef FIX_HRTF_LOAD *nSamplesRendered = 0; move16(); - +#endif IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; +#ifndef FIX_HRTF_LOAD *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; +#endif } ELSE { *nTransportChannels = 1; +#ifndef FIX_HRTF_LOAD *nOutChannels = 1; +#endif } +#ifndef FIX_HRTF_LOAD move16(); +#endif move16(); } ELSE @@ -1641,7 +1665,11 @@ static ivas_error IVAS_DEC_Setup( } } +#ifdef FIX_HRTF_LOAD + IF( NE_32( ( error = ivas_dec_setup( st_ivas ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -1717,8 +1745,10 @@ static ivas_error IVAS_DEC_Setup( *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; *nTcBufferGranularity = (UWord16) st_ivas->hTcBuffer->n_samples_granularity; +#ifndef FIX_HRTF_LOAD *nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out; move16(); +#endif move16(); move16(); @@ -1938,6 +1968,24 @@ static ivas_error IVAS_DEC_GetRenderedSamples( st_ivas = hIvasDec->st_ivas; +#ifdef FIX_HRTF_LOAD + Word16 nOutChannels = st_ivas->hDecoderConfig->nchan_out; + move16(); + hIvasDec->hasBeenFedFrame = false; + + /* check for possible flushed samples from a rate switch */ + IF( hIvasDec->nSamplesFlushed > 0 ) + { + /* note: offset (rendered samples) is always 0 */ + Copy( hIvasDec->flushbuffer, pcmBuf, hIvasDec->nSamplesFlushed * nOutChannels ); + + *nSamplesRendered = hIvasDec->nSamplesFlushed; + hIvasDec->nSamplesFlushed = 0; + move16(); + move16(); + } + +#endif /* run the main IVAS decoding routine */ error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); @@ -2701,6 +2749,7 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( return IVAS_ERR_OK; } + #ifdef FIX_CREND_SIMPLIFY_CODE /*---------------------------------------------------------------------* * IVAS_DEC_HRTF_binary_open( ) @@ -2729,7 +2778,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( /* TD binaural renderer */ test(); test(); - IF( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfTD == NULL ) + IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfTD == NULL ) { IF( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { @@ -2740,7 +2789,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( /* Crend binaural renderer */ test(); test(); - IF( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfCrend == NULL ) + IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_CREND ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfCrend == NULL ) { IF( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hHrtfCrend ) ) ) != IVAS_ERR_OK ) { @@ -2751,7 +2800,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( /* FastConv binaural renderer */ test(); test(); - IF( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfFastConv == NULL ) + IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfFastConv == NULL ) { IF( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { @@ -2762,7 +2811,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( /* Parametric binaural renderer */ test(); test(); - IF( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfParambin == NULL ) + IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_PARAMBIN ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfParambin == NULL ) { IF( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { @@ -2773,7 +2822,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( test(); test(); test(); - IF( st_ivas->hHrtfStatistics == NULL && ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + IF( st_ivas->hHrtfStatistics == NULL && ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_CREND ) ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { IF( ( error = ivas_HRTF_statistics_binary_open( &st_ivas->hHrtfStatistics ) ) != IVAS_ERR_OK ) { @@ -2785,6 +2834,7 @@ ivas_error IVAS_DEC_HRTF_binary_open( return IVAS_ERR_OK; } + /*---------------------------------------------------------------------* * IVAS_DEC_HRTF_binary_close( ) * @@ -2845,6 +2895,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( } #endif + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -3602,6 +3653,37 @@ ivas_error IVAS_DEC_ReadFormat( } } } + +#ifdef FIX_HRTF_LOAD + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_32( renderer_type_old, st_ivas->renderer_type ) && NE_32( renderer_type_old, RENDERER_DISABLE ) ) || + ( st_ivas->ini_active_frame > 0 && ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + { + /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + Word16 tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + + // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue #1200 + + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue #1199 + } + + IF( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif } st_ivas->ism_mode = ism_mode_old; @@ -3619,6 +3701,8 @@ ivas_error IVAS_DEC_ReadFormat( return IVAS_ERR_OK; } #endif + + /*---------------------------------------------------------------------* * IVAS_DEC_VoIP_GetSamples( ) * @@ -3759,6 +3843,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { return error; } + #ifdef FIX_CREND_SIMPLIFY_CODE *bitstreamReadDone = true; #endif @@ -3802,6 +3887,15 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } +#ifdef FIX_HRTF_LOAD + test(); + IF( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true ) + { + /* new bitstream was feeded, return for reconfiguration */ + return IVAS_ERR_OK; + } + +#endif IF( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; diff --git a/lib_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index d610a4a08..d957215d7 100644 --- a/lib_isar/lib_isar_post_rend.c +++ b/lib_isar/lib_isar_post_rend.c @@ -1118,7 +1118,11 @@ ivas_error ISAR_POST_REND_InitConfig( hIvasRend->splitRenderConfig.isar_frame_size_ms = 0; /* 0 means "use default for selected codec" */ hIvasRend->splitRenderConfig.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; hIvasRend->splitRenderConfig.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB; +#ifdef FIX_HRTF_LOAD + hIvasRend->splitRenderConfig.rendererSelection = IVAS_BIN_RENDERER_TYPE_DEFAULT; +#else hIvasRend->splitRenderConfig.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; +#endif } return IVAS_ERR_OK; diff --git a/lib_rend/ivas_crend_fx.c b/lib_rend/ivas_crend_fx.c index 565bfd380..60849b7ba 100644 --- a/lib_rend/ivas_crend_fx.c +++ b/lib_rend/ivas_crend_fx.c @@ -2226,6 +2226,7 @@ void ivas_rend_closeCldfbRend( * * Convolver block *-----------------------------------------------------------------------------------------*/ + #ifdef FIX_CREND_SIMPLIFY_CODE static ivas_error ivas_rend_crendConvolver( const CREND_WRAPPER *pCrend, diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index afcaa5ae1..66cc455eb 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -456,12 +456,15 @@ void ivas_dirac_dec_close_binaural_data( return; } + + /*------------------------------------------------------------------------- * ivas_dirac_dec_binaural_copy_hrtfs() * * Temporary function for copying HRTF data from rom tables if no binary * file was given. *------------------------------------------------------------------------*/ + ivas_error ivas_dirac_dec_binaural_copy_hrtfs_fx( HRTFS_PARAMBIN_HANDLE *hHrtfParambin /* i/o: HRTF structure for rendering */ ) @@ -511,17 +514,18 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs_fx( Copy32( parametricEarlyPartEneCorrection_fx, hrtfParambin->parametricEarlyPartEneCorrection_fx, CLDFB_NO_CHANNELS_MAX ); /*Q28*/ #endif *hHrtfParambin = hrtfParambin; - } - return IVAS_ERR_OK; + return IVAS_ERR_OK; + } } /*------------------------------------------------------------------------- - * void ivas_dirac_dec_binaural_render_fx() + * void ivas_dirac_dec_binaural_render() * * *------------------------------------------------------------------------*/ + void ivas_dirac_dec_binaural_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -4867,7 +4871,7 @@ static void getDirectPartGains_fx( Word16 aziRadMapped, A, A2, A3; const Word16 LsAngleRad = 17157; // Q15 move16(); - Word32 *ptr_sin, *ptr_cos; + const Word32 *ptr_sin, *ptr_cos; Word32 sin_val, cos_val; Word16 e_mappedX; diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index 8cfb7d18e..83615cfb7 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -3542,7 +3542,7 @@ void rotateAziEle_DirAC_fx( Word32 dv_0_fx, dv_1_fx, dv_2_fx; Word32 dv_r_0_fx, dv_r_1_fx, dv_r_2_fx, tmp, w_fx; Word16 exp, temp; - Word32 *ptr_sin, *ptr_cos; + const Word32 *ptr_sin, *ptr_cos; ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] q31 ptr_cos = cosine_table_Q31; // q31 diff --git a/lib_rend/ivas_hrtf_fx.c b/lib_rend/ivas_hrtf_fx.c index 89b11b66d..712213775 100644 --- a/lib_rend/ivas_hrtf_fx.c +++ b/lib_rend/ivas_hrtf_fx.c @@ -109,28 +109,7 @@ ivas_error ivas_HRTF_CRend_binary_open_fx( /*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_uint16() - * - * Allocate buffer with dynamic length for HRTF binary Crend handle - *-----------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( - UWord16 **buffer, /* o : buffer to allocate */ - const UWord32 mem_size /* i : size of buffer */ -) -{ - *buffer = (UWord16 *) malloc( mem_size ); - - if ( *buffer == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); - } - - return IVAS_ERR_OK; -} - -/*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_uint16() + * ivas_HRTF_CRend_binary_open_buffers_int16() * * Allocate buffer with dynamic length for HRTF binary Crend handle *-----------------------------------------------------------------------*/ @@ -150,49 +129,6 @@ ivas_error ivas_HRTF_CRend_binary_open_buffers_int16( return IVAS_ERR_OK; } - -/*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_float() - * - * Allocate buffer with dynamic length for HRTF binary Crend handle - *-----------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_CRend_binary_open_buffers_float( - float **buffer, /* o : buffer to allocate */ - const UWord32 mem_size /* i : size of buffer */ -) -{ - *buffer = (float *) malloc( mem_size ); - - IF( *buffer == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); - } - - return IVAS_ERR_OK; -} - -/*-----------------------------------------------------------------------* - * ivas_HRTF_CRend_binary_open_buffers_int32() - * - * Allocate buffer with dynamic length for HRTF binary Crend handle - *-----------------------------------------------------------------------*/ - -ivas_error ivas_HRTF_CRend_binary_open_buffers_int32( - Word32 **buffer, /* o : buffer to allocate */ - const UWord32 mem_size /* i : size of buffer */ -) -{ - *buffer = (Word32 *) malloc( mem_size ); - - IF( *buffer == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); - } - - return IVAS_ERR_OK; -} - #else /*-----------------------------------------------------------------------* * ivas_HRTF_CRend_binary_open() @@ -300,6 +236,7 @@ void ivas_HRTF_CRend_binary_close_fx( } #endif + /*-----------------------------------------------------------------------* * ivas_HRTF_fastconv_binary_open() * @@ -314,7 +251,9 @@ ivas_error ivas_HRTF_fastconv_binary_open_fx( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" ); } + ivas_init_binaural_hrtf_fx( *hHrtfFastConv ); + return IVAS_ERR_OK; } @@ -462,17 +401,17 @@ ivas_error ivas_HRTF_statistics_init( { case 48000: HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->average_energy_l_dyn == NULL ) + IF( HrtfStatistics->average_energy_l_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->average_energy_r_dyn == NULL ) + IF( HrtfStatistics->average_energy_r_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->inter_aural_coherence_dyn == NULL ) + IF( HrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } @@ -491,17 +430,17 @@ ivas_error ivas_HRTF_statistics_init( break; case 32000: HrtfStatistics->average_energy_l_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->average_energy_l_dyn == NULL ) + IF( HrtfStatistics->average_energy_l_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } HrtfStatistics->average_energy_r_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->average_energy_r_dyn == NULL ) + IF( HrtfStatistics->average_energy_r_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } HrtfStatistics->inter_aural_coherence_dyn = (Word32 *) malloc( LR_IAC_LENGTH_NR_FC * sizeof( Word32 ) ); - if ( HrtfStatistics->inter_aural_coherence_dyn == NULL ) + IF( HrtfStatistics->inter_aural_coherence_dyn == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } @@ -552,6 +491,5 @@ ivas_error ivas_HRTF_statistics_init( *hHrtfStatistics = HrtfStatistics; - return IVAS_ERR_OK; } diff --git a/lib_rend/ivas_objectRenderer_sources_fx.c b/lib_rend/ivas_objectRenderer_sources_fx.c index 4c30f23de..5b18e8a43 100644 --- a/lib_rend/ivas_objectRenderer_sources_fx.c +++ b/lib_rend/ivas_objectRenderer_sources_fx.c @@ -853,8 +853,6 @@ ivas_error TDREND_SRC_Alloc( ivas_error error; TDREND_SRC_t *Src_p; - error = IVAS_ERR_OK; - move32(); *Src_pp = NULL; /* Allocate the TDREND_SRC_t variable */ @@ -877,7 +875,7 @@ ivas_error TDREND_SRC_Alloc( *Src_pp = Src_p; - return error; + return IVAS_ERR_OK; } /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_prot_rend_fx.h b/lib_rend/ivas_prot_rend_fx.h index 87b927ab7..b5a0a8d6e 100644 --- a/lib_rend/ivas_prot_rend_fx.h +++ b/lib_rend/ivas_prot_rend_fx.h @@ -617,23 +617,8 @@ ivas_error ivas_HRTF_CRend_binary_open_fx( HRTFS_CREND_DATA **hHrtfCrend /* i/o: Crend HRTF handle */ ); -ivas_error ivas_HRTF_CRend_binary_open_buffers_uint16( - uint16_t **buffer, /* o : buffer to allocate */ - const uint32_t mem_size /* i : size of buffer */ -); - -ivas_error ivas_HRTF_CRend_binary_open_buffers_float( - float **buffer, /* o : buffer to allocate */ - const uint32_t mem_size /* i : size of buffer */ -); - ivas_error ivas_HRTF_CRend_binary_open_buffers_int16( - int16_t **buffer, /* o : buffer to allocate */ - const uint32_t mem_size /* i : size of buffer */ -); - -ivas_error ivas_HRTF_CRend_binary_open_buffers_int32( - int32_t **buffer, /* o : buffer to allocate */ + int16_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ ); @@ -645,7 +630,6 @@ ivas_error ivas_HRTF_statistics_init( HRTFS_STATISTICS_HANDLE *hHrtfStatistics, /* i/o: HRTF statistics structure */ const int32_t sampleRate /* i : Sample rate */ ); - #else ivas_error ivas_HRTF_CRend_binary_open_fx( diff --git a/lib_rend/ivas_render_config_fx.c b/lib_rend/ivas_render_config_fx.c index 98e5a0b33..ca2d7ef9f 100644 --- a/lib_rend/ivas_render_config_fx.c +++ b/lib_rend/ivas_render_config_fx.c @@ -156,7 +156,11 @@ ivas_error ivas_render_config_init_from_rom_fx( move32(); ( *hRenderConfig )->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB; move32(); +#ifdef FIX_HRTF_LOAD + ( *hRenderConfig )->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_DEFAULT; +#else ( *hRenderConfig )->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; +#endif move32(); ( *hRenderConfig )->split_rend_config.lc3plus_highres = 0; move16(); diff --git a/lib_rend/ivas_rom_binauralRenderer.h b/lib_rend/ivas_rom_binauralRenderer.h index f794e0327..bfb82b461 100644 --- a/lib_rend/ivas_rom_binauralRenderer.h +++ b/lib_rend/ivas_rom_binauralRenderer.h @@ -59,37 +59,40 @@ extern const Word16 hrtfShCoeffs_factorQ_fx; extern const Word16 parametricReverberationTimes_factorQ_fx; extern const Word16 parametricReverberationEneCorrections_factorQ_fx; extern const Word16 parametricEarlyPartEneCorrection_factorQ_fx; -extern Word16 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ -extern Word16 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ -extern Word16 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ -extern Word16 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ -extern Word16 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ -extern Word16 hrtfShCoeffsRe_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; /* Q14 */ -extern Word16 hrtfShCoeffsIm_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; /* Q14 */ +extern const Word16 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern const Word16 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern const Word16 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern const Word16 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern const Word16 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern const Word16 hrtfShCoeffsRe_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; /* Q14 */ +extern const Word16 hrtfShCoeffsIm_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BINS]; /* Q14 */ + +extern const Word32 FASTCONV_HOA3_latency_s_fx; +extern const Word32 FASTCONV_HOA2_latency_s_fx; +extern const Word32 FASTCONV_FOA_latency_s_fx; -extern Word32 FASTCONV_HOA3_latency_s_fx; -extern Word32 FASTCONV_HOA2_latency_s_fx; -extern Word32 FASTCONV_FOA_latency_s_fx; /* Binaural rendering data set based on HRIRs */ extern const Word32 FASTCONV_HRIR_latency_s_fx; + /* Binaural rendering data set based on BRIRs */ extern const Word32 FASTCONV_BRIR_latency_s_fx; extern const Word16 FASTCONV_factor_Q_BRIR_latency_s_fx; -extern Word16 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ -extern Word16 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ -extern Word16 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ -extern Word16 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern const Word16 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern const Word16 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern const Word16 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern const Word16 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ + /* Reverberation parameters based on BRIRs for fastconv */ extern Word16 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; /* Q26 */ extern Word16 fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ diff --git a/lib_rend/ivas_rom_binauralRenderer_fx.c b/lib_rend/ivas_rom_binauralRenderer_fx.c index 568b25ae2..630740efb 100644 --- a/lib_rend/ivas_rom_binauralRenderer_fx.c +++ b/lib_rend/ivas_rom_binauralRenderer_fx.c @@ -43,14 +43,14 @@ /*------------------------------------------------------------------------- * Binaural rendering related ROM tables *------------------------------------------------------------------------*/ - +#ifdef DEBUGGING /* Binaural rendering data set based on HRIRs */ /* Tables generated by the script at "scripts/binauralRenderer_interface/run_generate_IVAS_tables.m */ /* Can be replaced by your own generated HRIR tables */ /* * Generated with Matlab version 9.3.0.713579 (R2017b) by MUXE6256 */ - +#endif #ifdef USE_FASTCONV_PARAMBIN_16BIT_ROM diff --git a/lib_rend/ivas_rom_binaural_crend_head.h b/lib_rend/ivas_rom_binaural_crend_head.h index 660b03fa1..e9a3a20ce 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.h +++ b/lib_rend/ivas_rom_binaural_crend_head.h @@ -47,8 +47,8 @@ #include "ivas_cnst.h" -extern Word32 sine_table_Q31 [361]; -extern Word32 cosine_table_Q31 [181]; +extern const Word32 sine_table_Q31 [361]; +extern const Word32 cosine_table_Q31 [181]; #ifdef FIX_CREND_SIMPLIFY_CODE @@ -70,8 +70,8 @@ extern const Word16 *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[B extern const Word16 CRendBin_Combined_HRIR_coeff_Q_48kHz_fx; extern const Word16 CRendBin_Combined_HRIR_coeff_re_48kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][240]; extern const Word16 CRendBin_Combined_HRIR_coeff_im_48kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][240]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -86,8 +86,8 @@ extern const Word16 *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[B extern const Word16 CRendBin_Combined_HRIR_coeff_Q_32kHz_fx; extern const Word16 CRendBin_Combined_HRIR_coeff_re_32kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][160]; extern const Word16 CRendBin_Combined_HRIR_coeff_im_32kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][160]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -102,8 +102,8 @@ extern const Word16 *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[B extern const Word16 CRendBin_Combined_HRIR_coeff_Q_16kHz_fx; extern const Word16 CRendBin_Combined_HRIR_coeff_re_16kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][80]; extern const Word16 CRendBin_Combined_HRIR_coeff_im_16kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][80]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; @@ -125,8 +125,8 @@ extern const Word16 *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAUR extern const Word16 CRendBin_FOA_HRIR_coeff_Q_48kHz_fx; extern const Word16 CRendBin_FOA_HRIR_coeff_re_48kHz_fx[FOA_CHANNELS][BINAURAL_CHANNELS][240]; extern const Word16 CRendBin_FOA_HRIR_coeff_im_48kHz_fx[FOA_CHANNELS][BINAURAL_CHANNELS][240]; -extern Word16 *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -157,8 +157,8 @@ extern const Word16 *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAUR extern const Word16 CRendBin_FOA_HRIR_coeff_Q_16kHz_fx; extern const Word16 CRendBin_FOA_HRIR_coeff_re_16kHz_fx[FOA_CHANNELS][BINAURAL_CHANNELS][80]; extern const Word16 CRendBin_FOA_HRIR_coeff_im_16kHz_fx[FOA_CHANNELS][BINAURAL_CHANNELS][80]; -extern Word16 *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; @@ -180,8 +180,8 @@ extern const Word16 *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAU extern const Word16 CRendBin_HOA2_HRIR_coeff_Q_48kHz_fx; extern const Word16 CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[HOA2_CHANNELS][BINAURAL_CHANNELS][240]; extern const Word16 CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[HOA2_CHANNELS][BINAURAL_CHANNELS][240]; -extern Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -212,8 +212,8 @@ extern const Word16 *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAU extern const Word16 CRendBin_HOA2_HRIR_coeff_Q_16kHz_fx; extern const Word16 CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[HOA2_CHANNELS][BINAURAL_CHANNELS][80]; extern const Word16 CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[HOA2_CHANNELS][BINAURAL_CHANNELS][80]; -extern Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; @@ -235,8 +235,8 @@ extern const Word16 *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAU extern const Word16 CRendBin_HOA3_HRIR_coeff_Q_48kHz_fx; extern const Word16 CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[HOA3_CHANNELS][BINAURAL_CHANNELS][240]; extern const Word16 CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[HOA3_CHANNELS][BINAURAL_CHANNELS][240]; -extern Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -251,8 +251,8 @@ extern const Word16 *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAU extern const Word16 CRendBin_HOA3_HRIR_coeff_Q_32kHz_fx; extern const Word16 CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[HOA3_CHANNELS][BINAURAL_CHANNELS][160]; extern const Word16 CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[HOA3_CHANNELS][BINAURAL_CHANNELS][160]; -extern Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; -extern Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; +extern const Word16 *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -290,8 +290,8 @@ extern const Word16 CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[BI extern const Word16 CRendBin_Combined_BRIR_coeff_Q_48kHz_fx; extern const Word16 CRendBin_Combined_BRIR_coeff_re_48kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][2955]; extern const Word16 CRendBin_Combined_BRIR_coeff_im_48kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][2955]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS][2885]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS][2885]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS][2885]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS][2885]; /* Sample Rate = 32000 */ @@ -306,8 +306,8 @@ extern const Word16 CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[BI extern const Word16 CRendBin_Combined_BRIR_coeff_Q_32kHz_fx; extern const Word16 CRendBin_Combined_BRIR_coeff_re_32kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][2818]; extern const Word16 CRendBin_Combined_BRIR_coeff_im_32kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][2818]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS][2868]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS][2868]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS][2868]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS][2868]; /* Sample Rate = 16000 */ @@ -322,8 +322,8 @@ extern const Word16 CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[BI extern const Word16 CRendBin_Combined_BRIR_coeff_Q_16kHz_fx; extern const Word16 CRendBin_Combined_BRIR_coeff_re_16kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][1799]; extern const Word16 CRendBin_Combined_BRIR_coeff_im_16kHz_fx[HRTF_LS_CHANNELS][BINAURAL_CHANNELS][1799]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS][2474]; -extern Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS][2474]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS][2474]; +extern const Word16 CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS][2474]; #ifdef USE_REVERB_16BIT_ROM /********************** default HRIR reverb rom tables **********************/ diff --git a/lib_rend/ivas_rom_binaural_crend_head_fx.c b/lib_rend/ivas_rom_binaural_crend_head_fx.c index 1849f19e2..108e34769 100644 --- a/lib_rend/ivas_rom_binaural_crend_head_fx.c +++ b/lib_rend/ivas_rom_binaural_crend_head_fx.c @@ -67489,7 +67489,7 @@ const float defaultHRIR_right_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC_16KHZ] = #endif -Word32 sine_table_Q31 [361] = { +const Word32 sine_table_Q31 [361] = { 187, -37478868, -74946000, -112390808, -149800880, -187165824, -224473232, -261712288, -298872128, -335940416, -372906880, -409759232, -446486784, -483078848, -519523232, -555809856, -591926720, -627863744, -663609024, -699152192, -734482816, @@ -67529,7 +67529,8 @@ Word32 sine_table_Q31 [361] = { 335940416, 298872128, 261712288, 224473232, 187165824, 149800880, 112390808, 74946000, 37478868, -187, }; -Word32 cosine_table_Q31 [181] = { + +const Word32 cosine_table_Q31[181] = { 2147483647, 2147156608, 2146175488, 2144540544, 2142252544, 2139311872, 2135719552, 2131476608, 2126584448, 2121044608, 2114858496, 2108028288, 2100556032, 2092443776, 2083694208, 2074309888, 2064293760, 2053648896, 2042378368, 2030485632, 2017974528, diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index b3b0e55b1..e761a8f15 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1343,6 +1343,7 @@ typedef struct /*------------------------------------------------------------------------------------------* * Crend structures *------------------------------------------------------------------------------------------*/ + #ifdef FIX_CREND_SIMPLIFY_CODE typedef struct ivas_hrtf_crend_structure #else diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 0d234814c..ab83057a4 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -3092,11 +3092,14 @@ static ivas_error updateSbaPanGains( case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED: case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM: { +#ifdef FIX_HRTF_LOAD + IF( EQ_32( hRendCfg->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else IF( EQ_32( hRendCfg->split_rend_config.rendererSelection, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) ) - +#endif { assert( inConfig == IVAS_AUDIO_CONFIG_HOA3 && ( *rendCtx.pOutSampleRate == 48000 ) && "split binaural fast conv mode is currently supported with HOA3 input and 48k sampling rate only" ); - if ( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3104,7 +3107,7 @@ static ivas_error updateSbaPanGains( else { assert( ( *rendCtx.pOutSampleRate == 48000 ) && "split binaural crend mode is currently supported with 48k sampling rate only" ); - if ( ( error = ivas_rend_openMultiBinCrend( &inputSba->crendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openMultiBinCrend( &inputSba->crendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -3116,9 +3119,13 @@ static ivas_error updateSbaPanGains( case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: #endif { +#ifdef FIX_HRTF_LOAD + IF( EQ_32( hRendCfg->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else if ( hRendCfg->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { - if ( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -4030,7 +4037,11 @@ static Word16 getCldfbRendFlag( isCldfbRend = 0; move16(); } +#ifdef FIX_HRTF_LOAD + ELSE IF( GT_16( numMasaInputs, 0 ) || ( GT_16( numSbaInputs, 0 ) && EQ_32( hIvasRend->hRendererConfig->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) ) +#else ELSE IF( GT_16( numMasaInputs, 0 ) || ( GT_16( numSbaInputs, 0 ) && EQ_32( hIvasRend->hRendererConfig->split_rend_config.rendererSelection, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) ) ) +#endif { isCldfbRend = 1; move16(); @@ -4622,7 +4633,6 @@ ivas_error IVAS_REND_GetDelay_fx( { latency_ns = 0; } - move32(); latency_ns = L_max( latency_ns, hIvasRend->inputsMc[i].tdRendWrapper.binaural_latency_ns ); @@ -4637,7 +4647,11 @@ ivas_error IVAS_REND_GetDelay_fx( test(); IF( hIvasRend->splitRendWrapper != NULL && hIvasRend->splitRendWrapper->hBinHrSplitPreRend != NULL ) { +#ifdef FIX_HRTF_LOAD + IF( EQ_32( hIvasRend->hRendererConfig->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else IF( hIvasRend->hRendererConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { latency_ns = hIvasRend->inputsSba[i].cldfbRendWrapper.binaural_latency_ns; move32(); @@ -7791,17 +7805,21 @@ static ivas_error renderSbaToSplitBinaural( push_wmops( "renderSbaToSplitBinaural" ); +#ifdef FIX_HRTF_LOAD + IF( EQ_32( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else IF( EQ_32( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) ) +#endif { - if ( ( error = renderSbaToMultiBinauralCldfb( sbaInput, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, low_res_pre_rend_rot, - getNumSubframesInBuffer( &outAudio, *sbaInput->base.ctx.pOutSampleRate ), *outAudio.pq_fact ) ) != IVAS_ERR_OK ) + IF( ( error = renderSbaToMultiBinauralCldfb( sbaInput, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, low_res_pre_rend_rot, + getNumSubframesInBuffer( &outAudio, *sbaInput->base.ctx.pOutSampleRate ), *outAudio.pq_fact ) ) != IVAS_ERR_OK ) { return error; } accumulateCLDFBArrayToBuffer_fx( Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, &outAudio ); } - else + ELSE { IF( ( error = renderSbaToMultiBinaural( sbaInput, outConfig, tmpCrendBuffer, outAudio.pq_fact ) ) != IVAS_ERR_OK ) { @@ -7838,7 +7856,11 @@ static ivas_error renderSbaToBinaural( push_wmops( "renderSbaToBinaural" ); +#ifdef FIX_HRTF_LOAD + IF( EQ_32( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection, IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else IF( EQ_32( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) ) +#endif { Word32 Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; @@ -9070,7 +9092,7 @@ static ivas_error getSamplesInternal( if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, hIvasRend->headRotData.headPositions[0], hIvasRend->hRendererConfig->split_rend_config.splitRendBitRate, hIvasRend->hRendererConfig->split_rend_config.codec, hIvasRend->hRendererConfig->split_rend_config.isar_frame_size_ms, hIvasRend->hRendererConfig->split_rend_config.codec_frame_size_ms, - &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, ( const Word16 )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) + &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, (const Word16) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index db73488bd..43273f78b 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -250,14 +250,16 @@ static ivas_error read_hrtf_binary_header( ivas_hrtfs_header_t *hrtf_header, FILE *f_hrtf ) { + #ifdef FIX_CREND_SIMPLIFY_CODE if ( hrtf_header == NULL || f_hrtf == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } #endif + /* HRTF Header */ - /* Renderer type (4 bytes) : See "HRTF_READER_RENDERER_TYPE" */ + /* Renderer type (4 bytes) : See "HRTF_READER_RENDERER_TYPE" */ /* Input configuration (4 bytes) : See "BINAURAL_INPUT_AUDIO_CONFIG" */ /* Sampling Frequency (4 bytes) */ /* Raw data size (4 bytes) */ @@ -270,6 +272,7 @@ static ivas_error read_hrtf_binary_header( return IVAS_ERR_END_OF_FILE; } + #ifdef FIX_CREND_SIMPLIFY_CODE /*-------------------------------------------------------------------* * audio_cfg_2_binaural_cfg() @@ -1082,11 +1085,11 @@ static ivas_error load_reverb_from_binary( #ifndef FIX_CREND_SIMPLIFY_CODE float f_tmp_lr_energy_and_iac_dyn[LR_IAC_LENGTH_NR_FC]; #endif - #ifdef FIX_CREND_SIMPLIFY_CODE int16_t ind; Word16 factorQ; Word16 tmp16; + if ( hHrtfStatistics == NULL || f_hrtf == NULL ) #else if ( hHrtfStatistics == NULL ) @@ -1612,6 +1615,7 @@ void destroy_td_hrtf( return; } + #ifdef FIX_CREND_SIMPLIFY_CODE /*---------------------------------------------------------------------* * create_Crend_HRTF_from_rawdata() @@ -2840,7 +2844,6 @@ ivas_error load_fastconv_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; int16_t asFastconv = 0; - #ifdef FIX_CREND_SIMPLIFY_CODE bool load = false; BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; @@ -2884,6 +2887,7 @@ ivas_error load_fastconv_HRTF_from_binary( free( hrtf_data ); return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } + #ifdef FIX_CREND_SIMPLIFY_CODE if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && /* HRIRs */ ( OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL || OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) || @@ -3041,6 +3045,7 @@ ivas_error load_parambin_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; int16_t asParam = 0; + #ifdef FIX_CREND_SIMPLIFY_CODE if ( hrtfReader == NULL || hrtfReader->file == NULL ) { @@ -3081,7 +3086,6 @@ ivas_error load_parambin_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } - #ifdef FIX_CREND_SIMPLIFY_CODE if ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_PARAMETRIC ) /* Parametric binauralizer data is represented as single entity */ #else @@ -3094,6 +3098,7 @@ ivas_error load_parambin_HRTF_from_binary( return IVAS_ERR_INVALID_HRTF_SAMPLING_RATE; } #endif + if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { free( hrtf_data ); @@ -3104,6 +3109,7 @@ ivas_error load_parambin_HRTF_from_binary( if ( ( create_parambin_HRTF_from_rawdata( &hHrtfParamBin, hrtf_data ) ) != IVAS_ERR_OK ) { free( hrtf_data ); + #ifdef FIX_CREND_SIMPLIFY_CODE return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create ParamBin HRTF from binary file" ); #else @@ -3128,6 +3134,7 @@ ivas_error load_parambin_HRTF_from_binary( } } + #ifdef FIX_CREND_SIMPLIFY_CODE /*---------------------------------------------------------------------* * load_Crend_HRTF_from_binary() @@ -3235,6 +3242,7 @@ ivas_error load_Crend_HRTF_from_binary( } free( hrtf_data ); + return IVAS_ERR_OK; } #else @@ -3344,6 +3352,8 @@ ivas_error create_SetOfHRTF_from_binary( return IVAS_ERR_OK; } #endif + + /*---------------------------------------------------------------------* * destroy_crend_hrtf() * @@ -3363,7 +3373,6 @@ static void destroy_HRTF( uint16_t i, j; test(); - test(); #ifdef FIX_CREND_SIMPLIFY_CODE if ( *hHrtfCrend != NULL && hHrtfCrend != NULL ) { @@ -3473,6 +3482,7 @@ void destroy_SetOfHRTF( } #endif + /*---------------------------------------------------------------------* * destroy_hrtf_statistics() * @@ -3498,6 +3508,7 @@ void destroy_hrtf_statistics( free( ( *hHrtfStatistics )->inter_aural_coherence_dyn ); } } + ivas_HRTF_statistics_close( hHrtfStatistics ); #ifdef FIX_CREND_SIMPLIFY_CODE diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 1d5f111ac..6d4b61cae 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -2540,19 +2540,35 @@ ivas_error RenderConfigReader_read( { if ( strcmp( pValue, "CREND" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_CREND; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_CREND; +#endif } else if ( strcmp( pValue, "FASTCONV" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_FASTCONV; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; +#endif } else if ( strcmp( pValue, "PARAMBIN" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_PARAMBIN; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN; +#endif } else if ( strcmp( pValue, "TDREND" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_TDREND; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND; +#endif } else { -- GitLab From a3990a1b6712a65d00ac8c5e4338fbdd685b0715 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 19 Sep 2025 22:33:12 +0200 Subject: [PATCH 12/19] updates --- apps/decoder.c | 55 +++++++++++++++++++++++---------------- lib_dec/ivas_ism_dec_fx.c | 2 +- lib_dec/ivas_mct_dec_fx.c | 3 ++- lib_dec/lib_dec.h | 10 +++---- lib_dec/lib_dec_fx.c | 45 +++++++++++++++++++++++++------- lib_rend/lib_rend_fx.c | 2 +- 6 files changed, 78 insertions(+), 39 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 133bc23e9..5c785db39 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -2691,6 +2691,7 @@ static ivas_error decodeVoIP( int16_t nOutSamples = 0; #ifdef FIX_CREND_SIMPLIFY_CODE bool bitstreamReadDone = false; + uint16_t nSamplesRendered; #endif vec_pos_update = 0; @@ -2809,6 +2810,9 @@ static ivas_error decodeVoIP( while ( 1 ) { +#ifdef FIX_CREND_SIMPLIFY_CODE + nSamplesRendered = 0; +#endif /* reference vector */ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) @@ -2972,11 +2976,15 @@ static ivas_error decodeVoIP( /* decode and get samples */ +#ifdef FIX_HRTF_LOAD + while ( nSamplesRendered < nOutSamples ) + { +#endif #ifdef SUPPORT_JBM_TRACEFILE #ifdef FIX_CREND_SIMPLIFY_CODE - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered ) ) != IVAS_ERR_OK ) #else - if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK ) #endif #else #ifdef FIX_CREND_SIMPLIFY_CODE @@ -2985,34 +2993,37 @@ static ivas_error decodeVoIP( 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 ) ); - goto cleanup; - } + { + fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } #ifdef FIX_CREND_SIMPLIFY_CODE - if ( bitstreamReadDone == true ) - { - /* Read main parameters from the bitstream to set-up the decoder */ - hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) + if ( bitstreamReadDone == true ) { - return error; - } + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Placeholder for memory reallocation */ - /* ... */ + /* Placeholder for memory reallocation */ + /* ... */ - /* Load HRTF binary file data */ - if ( arg.hrtfReaderEnabled ) - { - if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) { - fprintf( stderr, "\nload_hrtf_from_file failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; + if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nload_hrtf_from_file failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } } } +#endif +#ifdef FIX_HRTF_LOAD } #endif diff --git a/lib_dec/ivas_ism_dec_fx.c b/lib_dec/ivas_ism_dec_fx.c index 4d5aeecff..ab404b2a9 100644 --- a/lib_dec/ivas_ism_dec_fx.c +++ b/lib_dec/ivas_ism_dec_fx.c @@ -182,7 +182,7 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ ELSE - IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index c8f23adc6..1a745c4a2 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -1031,7 +1031,8 @@ static ivas_error ivas_mc_dec_reconfig_fx( #endif } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ - ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) + ELSE + IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index d0e887114..0dc09e135 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -273,14 +273,14 @@ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ - const UWord32 systemTimestamp_ms /* i : current system timestamp */ + const UWord32 systemTimestamp_ms, /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE - , JbmTraceFileWriterFn jbmWriterFn, - void* jbmWriter + JbmTraceFileWriterFn jbmWriterFn, + void* jbmWriter, #endif #ifdef FIX_CREND_SIMPLIFY_CODE -, - bool *bitstreamReadDone /* o : flag indicating that bitstream was read */ + bool *bitstreamReadDone, /* o : flag indicating that bitstream was read */ + UWord16 *nSamplesRendered /* o : number of samples rendered */ #endif ); diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 58396d862..ded16a7e3 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -3710,18 +3710,17 @@ ivas_error IVAS_DEC_ReadFormat( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_VoIP_GetSamples( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ - const UWord32 systemTimestamp_ms /* i : current system timestamp */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */ + const UWord32 systemTimestamp_ms, /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE - , JbmTraceFileWriterFn jbmWriterFn, - void *jbmWriter + void *jbmWriter, #endif #ifdef FIX_CREND_SIMPLIFY_CODE - , - bool *bitstreamReadDone /* o : flag indicating that bitstream was read */ + bool *bitstreamReadDone, /* o : that bitstream was read */ + UWord16 *nSamplesRendered /* o : number of samples rendered */ #endif ) { @@ -3733,7 +3732,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples( UWord16 extBufferedSamples; Word16 result; ivas_error error; +#ifndef FIX_CREND_SIMPLIFY_CODE Word16 nSamplesRendered; +#endif UWord8 nOutChannels; test(); @@ -3747,7 +3748,9 @@ ivas_error IVAS_DEC_VoIP_GetSamples( hDecoderConfig = st_ivas->hDecoderConfig; hVoIP = hIvasDec->hVoIP; nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out; +#ifndef FIX_CREND_SIMPLIFY_CODE nSamplesRendered = 0; +#endif move16(); move16(); move16(); @@ -3757,8 +3760,12 @@ ivas_error IVAS_DEC_VoIP_GetSamples( return IVAS_ERR_WRONG_PARAMS; } - /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ +/* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ +#ifdef FIX_CREND_SIMPLIFY_CODE + WHILE( LT_16( *nSamplesRendered, nSamplesPerChannel ) ) +#else WHILE( LT_16( nSamplesRendered, nSamplesPerChannel ) ) +#endif { IF( hIvasDec->nSamplesAvailableNext == 0 ) { @@ -3911,8 +3918,13 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /* codec mode to use not known yet - simply output silence */ /* directly set output zero */ Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); +#ifdef FIX_CREND_SIMPLIFY_CODE + set16_fx( pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) ); + *nSamplesRendered = add( *nSamplesRendered, nSamplesToZero ); +#else set16_fx( pcmBuf + imult1616( nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) ); nSamplesRendered = add( nSamplesRendered, nSamplesToZero ); +#endif hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero ); hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero ); move16(); @@ -3923,15 +3935,30 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { Word16 nSamplesToRender, nSamplesRendered_loop; bool tmp; +#ifdef FIX_CREND_SIMPLIFY_CODE + nSamplesToRender = sub( nSamplesPerChannel, *nSamplesRendered ); +#else nSamplesToRender = sub( nSamplesPerChannel, nSamplesRendered ); +#endif /* render IVAS frames directly to the output buffer */ +#ifdef FIX_CREND_SIMPLIFY_CODE + IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) +#endif { return error; } +#ifdef FIX_HRTF_LOAD + *bitstreamReadDone = false; // temp hack until JBM API is reworked +#endif +#ifdef FIX_CREND_SIMPLIFY_CODE + *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); +#else nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); +#endif update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop ); } } diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index ab83057a4..68ad09d67 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -9092,7 +9092,7 @@ static ivas_error getSamplesInternal( if ( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( hIvasRend->splitRendWrapper, hIvasRend->headRotData.headPositions[0], hIvasRend->hRendererConfig->split_rend_config.splitRendBitRate, hIvasRend->hRendererConfig->split_rend_config.codec, hIvasRend->hRendererConfig->split_rend_config.isar_frame_size_ms, hIvasRend->hRendererConfig->split_rend_config.codec_frame_size_ms, - &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, (const Word16) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) + &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, ( const Word16 )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, ( hIvasRend->outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 67dbc18f528ff7d3fed5e5e4f186a122d1dcf0f1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 10:53:28 +0200 Subject: [PATCH 13/19] fix ivas_dec_get_format_fx() for OSBA decoding --- lib_dec/ivas_init_dec_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 6fbd4f28b..dc916babf 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -336,7 +336,11 @@ ivas_error ivas_dec_get_format_fx( /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ sba_order = st_ivas->bit_stream[num_bits_read + 1]; move16(); +#ifdef FIX_HRTF_LOAD + sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); +#else sba_order = shl( st_ivas->bit_stream[num_bits_read], 1 ); +#endif num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); /* read the real Ambisonic order when the above bits are used to signal OSBA format */ -- GitLab From 810ab22d75db891c53b553add2064a01d109b2bf Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 12:37:46 +0200 Subject: [PATCH 14/19] fix ivas_dec_get_format_fx() for OSBA and OMASA decoding --- lib_dec/ivas_init_dec_fx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index dc916babf..a03924573 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -252,7 +252,7 @@ ivas_error ivas_dec_get_format_fx( /* this should be non-zero if original input format was MASA_ISM_FORMAT */ st_ivas->ism_mode = ISM_MODE_NONE; move16(); - nchan_ism = st_ivas->bit_stream[k - 3] + shl( st_ivas->bit_stream[k - 2], 1 ); + nchan_ism = add( st_ivas->bit_stream[k - 3], shl( st_ivas->bit_stream[k - 2], 1 ) ); IF( nchan_ism > 0 ) { @@ -266,11 +266,19 @@ ivas_error ivas_dec_get_format_fx( */ nchan_ism = sub( 5, nchan_ism ); test(); +#ifdef FIX_HRTF_LOAD + IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + nchan_ism = 1; + move16(); + } +#else IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( st_ivas->nchan_ism, 2 ) ) { st_ivas->nchan_ism = 1; move16(); } +#endif /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ st_ivas->nchan_transport = 2; @@ -337,7 +345,7 @@ ivas_error ivas_dec_get_format_fx( sba_order = st_ivas->bit_stream[num_bits_read + 1]; move16(); #ifdef FIX_HRTF_LOAD - sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); #else sba_order = shl( st_ivas->bit_stream[num_bits_read], 1 ); #endif -- GitLab From d53c42dd59a391a667586629ce5608a49064b878 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 14:05:56 +0200 Subject: [PATCH 15/19] fix flush --- lib_dec/ivas_init_dec_fx.c | 4 ++++ lib_dec/lib_dec_fx.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index a03924573..bb53a60b9 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -356,7 +356,11 @@ ivas_error ivas_dec_get_format_fx( { sba_order = st_ivas->bit_stream[num_bits_read + 1]; move16(); +#ifdef FIX_HRTF_LOAD + sba_order = add( sba_order, shl( st_ivas->bit_stream[num_bits_read], 1 ) ); +#else sba_order = shl( st_ivas->bit_stream[num_bits_read], 1 ); +#endif num_bits_read = add( num_bits_read, SBA_ORDER_BITS ); } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index ded16a7e3..b07e02860 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -99,7 +99,7 @@ struct IVAS_DEC #ifdef FIX_HRTF_LOAD UWord16 nSamplesFlushed; - Word16 *flushbuffer; + Word16 flushbuffer[20 * 960]; // temp. hack bool hasBeenPreparedRendering; #endif }; @@ -1969,6 +1969,8 @@ static ivas_error IVAS_DEC_GetRenderedSamples( st_ivas = hIvasDec->st_ivas; #ifdef FIX_HRTF_LOAD + // temp code to make HRTF changes working in the old API structure + UWord16 nSamplesRendered_loop = 0; Word16 nOutChannels = st_ivas->hDecoderConfig->nchan_out; move16(); hIvasDec->hasBeenFedFrame = false; @@ -1985,9 +1987,14 @@ static ivas_error IVAS_DEC_GetRenderedSamples( move16(); } -#endif + /* run the main IVAS decoding routine */ + error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, &nSamplesRendered_loop, nSamplesAvailableNext, pcmBuf ); + + *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); +#else /* run the main IVAS decoding routine */ error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); +#endif return error; } -- GitLab From 66f1fe5c4132cf38600b0efc6ab3607c1d51addc Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 17:27:08 +0200 Subject: [PATCH 16/19] fix flush --- lib_dec/lib_dec_fx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index b07e02860..81f7b5c68 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -99,7 +99,7 @@ struct IVAS_DEC #ifdef FIX_HRTF_LOAD UWord16 nSamplesFlushed; - Word16 flushbuffer[20 * 960]; // temp. hack + Word16 flushbuffer[20 * 960 / 4]; // temp. hack bool hasBeenPreparedRendering; #endif }; @@ -194,6 +194,10 @@ ivas_error IVAS_DEC_Open( move16(); move16(); move16(); +#ifdef FIX_HRTF_LOAD + hIvasDec->nSamplesFlushed = 0; + hIvasDec->hasBeenPreparedRendering = false; +#endif hIvasDec->mode = mode; move16(); @@ -1988,7 +1992,7 @@ static ivas_error IVAS_DEC_GetRenderedSamples( } /* run the main IVAS decoding routine */ - error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, &nSamplesRendered_loop, nSamplesAvailableNext, pcmBuf ); + error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering - *nSamplesRendered, &nSamplesRendered_loop, nSamplesAvailableNext, pcmBuf ); *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); #else -- GitLab From 3ce2cda06d5791c15e58446e546e70d080b1ddac Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 19:59:27 +0200 Subject: [PATCH 17/19] fix --- lib_dec/lib_dec_fx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 81f7b5c68..42ff9abb1 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -4027,6 +4027,9 @@ ivas_error IVAS_DEC_Flush( ivas_error error; UWord16 nSamplesToRender; UWord16 nSamplesFlushedLocal; +#ifdef FIX_HRTF_LOAD + nSamplesFlushedLocal = 0; // temp. hack +#endif test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) -- GitLab From c12ffce7f0ec46ba02b819c8fd8920744e6f6d5f Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 20 Sep 2025 21:15:17 +0200 Subject: [PATCH 18/19] fix --- lib_dec/lib_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 42ff9abb1..ec2a64ed8 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1992,7 +1992,7 @@ static ivas_error IVAS_DEC_GetRenderedSamples( } /* run the main IVAS decoding routine */ - error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering - *nSamplesRendered, &nSamplesRendered_loop, nSamplesAvailableNext, pcmBuf ); + error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering - *nSamplesRendered, &nSamplesRendered_loop, nSamplesAvailableNext, pcmBuf + ( *nSamplesRendered * nOutChannels ) ); *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop ); #else -- GitLab From a919c31cc8355f73cb6e5a405a1413c0ae9603ac Mon Sep 17 00:00:00 2001 From: vaclav Date: Sun, 21 Sep 2025 17:42:36 +0200 Subject: [PATCH 19/19] FIX_HRTF_LOAD_KEEP_BE --- lib_com/options.h | 1 + lib_dec/ivas_masa_dec_fx.c | 19 +++++++++++++------ lib_dec/lib_dec_fx.c | 22 +++++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 89d05dad3..345223a0a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -125,6 +125,7 @@ #define USE_TDREND_16BIT_ROM /* if desactivated old rom hrtf tables is used. when active some tests case with 4 ISM fail due to owerflow in round_fixed function */ #define USE_FASTCONV_PARAMBIN_16BIT_ROM /* if desactivated old rom hrtf tables is used */ #define FIX_HRTF_LOAD /* VA: issue 1187: fix memory issue when HRTFs are loaded from a binary file */ +#define FIX_HRTF_LOAD_KEEP_BE // VA: temp. hack to keep BE when FIX_HRTF_LOAD is activated - the code will be removed once HRTF updates are stable #endif #define NONBE_1377_REND_DIRATT_CONF /* Eri: Issue 1377: Error in directivity attenuation configuration for both IVAS_dec and IVAS_rend */ #define FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK /* Eri: Issue 1999: Range check on float values of distance attenuation, while the float values are not propagated to this function. The test is not correct, but configurable distance attenuation is not used in Characterization.*/ diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index 4851822db..e3964ae25 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -1807,16 +1807,23 @@ ivas_error ivas_masa_dec_reconfigure_fx( tmp = extract_l( Mpy_32_32( st_ivas->hSCE[sce_id]->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); num_bits = add( num_bits, tmp ); - test(); - test(); - test(); - IF( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] != NULL ) +#ifdef FIX_HRTF_LOAD_KEEP_BE + if ( ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ) >= st_ivas->hTcBuffer->n_samples_granularity ) { - IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) +#endif + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin[0] != NULL ) { - return error; + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) + { + return error; + } } +#ifdef FIX_HRTF_LOAD_KEEP_BE } +#endif } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index ec2a64ed8..d1c857d2e 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -3688,7 +3688,27 @@ ivas_error IVAS_DEC_ReadFormat( IF( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { - if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) +#ifdef FIX_HRTF_LOAD_KEEP_BE + if ( ivas_format_old == MASA_ISM_FORMAT && ism_mode_old == ISM_MASA_MODE_DISC ) + { + if ( st_ivas->hDiracDecBin[0] != NULL ) + { + IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin[0] != NULL ) + { + if ( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif + IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) { return error; } -- GitLab