From e8dd951423ffd8ef1aa78b2cff83ddd3523d787e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 14 Oct 2024 21:42:46 +0530 Subject: [PATCH] Conversion and integration of MASA/OMASA paths sub-functions, cleanup [x] ivas_masa_enc: reduce_metadata_further and move_metadata_to_qmetadata converted & integrated [x] ivas_qmetadata_enc_sid_encode conversion and integration [x] ivas_core_pre_proc_front, pre_proc_ivas, omasa_enc cleanup cleanup [x] ivas_param_mc_enc cleanup [x] Fix for LFE encoding and removed few overflow passthrough changes [x] Integration of merge masa transports [x] Q-info update for lib_dec files --- lib_com/cldfb.c | 7 + lib_com/ivas_filters.c | 50 +-- lib_com/ivas_prot.h | 12 + lib_com/ivas_prot_fx.h | 45 ++- lib_com/ivas_rom_com_fx.c | 22 ++ lib_com/ivas_rom_com_fx.h | 1 + lib_com/ivas_stat_com.h | 2 +- lib_com/options.h | 386 +++++++++--------- lib_com/prot_fx.h | 71 ++-- lib_com/stat_com.h | 4 +- lib_com/tec_com_flt.c | 4 +- lib_com/tools_fx.c | 40 +- lib_dec/cng_dec_fx.c | 192 +++++---- lib_dec/core_dec_init_fx.c | 390 ++++++++++--------- lib_dec/core_dec_reconf_fx.c | 38 +- lib_enc/acelp_core_enc.c | 16 +- lib_enc/core_enc_init.c | 12 +- lib_enc/core_enc_reconf.c | 4 + lib_enc/core_switching_enc.c | 33 +- lib_enc/enc_acelp.c | 2 + lib_enc/ivas_core_enc.c | 18 - lib_enc/ivas_core_pre_proc.c | 2 - lib_enc/ivas_dirac_enc.c | 24 ++ lib_enc/ivas_enc.c | 213 +++++++++- lib_enc/ivas_masa_enc.c | 650 +++++++++++++++++++++++++++++-- lib_enc/ivas_mc_param_enc.c | 372 ++++++------------ lib_enc/ivas_mc_paramupmix_enc.c | 38 +- lib_enc/ivas_omasa_enc.c | 487 ++++++++--------------- lib_enc/ivas_qmetadata_enc.c | 233 ++++++----- lib_enc/ivas_sce_enc.c | 8 +- lib_enc/ivas_stat_enc.h | 18 +- lib_enc/plc_enc_ext.c | 2 + lib_enc/stat_enc.h | 152 +++++--- lib_enc/swb_bwe_enc.c | 16 + lib_enc/swb_pre_proc.c | 2 + lib_enc/swb_tbe_enc.c | 39 +- lib_enc/swb_tbe_enc_fx.c | 1 + lib_enc/tcx_ltp_enc.c | 2 + lib_enc/transient_detection.c | 6 + 39 files changed, 2165 insertions(+), 1449 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index fa7a11611..2d0719eec 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -61,7 +61,9 @@ static void cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ); static void cldfb_init_proto_and_twiddles_enc( HANDLE_CLDFB_FILTER_BANK hs ); +#ifndef IVAS_FLOAT_FIXED static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead, float **realValues, float **imagValues, const int16_t numberBands, int16_t numberCols, TEC_ENC_HANDLE hTecEnc ); +#endif /*-------------------------------------------------------------------* * cplxMult() @@ -1917,6 +1919,7 @@ void resampleCldfb_ivas_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * analysisCLDFBEncoder() * @@ -1947,6 +1950,7 @@ void analysisCldfbEncoder_ivas( return; } +#endif void analysisCldfbEncoder_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ @@ -2005,6 +2009,8 @@ void analysisCldfbEncoder_ivas_fx( return; } + +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * GetEnergyCldfb_ivas() * @@ -2078,6 +2084,7 @@ static float GetEnergyCldfb_ivas( return 65535.0f; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index 21ec2a2a4..bc0a2fce2 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -46,7 +46,7 @@ #ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); #else -static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 q_fcator ); +static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, Word16 *pIn_Out_e ); #endif /*-----------------------------------------------------------------------------------------* * Function ivas_filters_init() @@ -237,17 +237,33 @@ void ivas_filter_process_fx( const Word16 length, /* i : filter order */ Word16 q_factor ) { + Word16 pIn_Out_e[L_FRAME_MAX]; + Word16 i; SWITCH( filter_state->order ) { case IVAS_FILTER_ORDER_1: case IVAS_FILTER_ORDER_2: - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor ); + set_val_Word16( pIn_Out_e, sub( Q31, q_factor ), length ); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); + /* Scale pIn_Out_fx back to input Q */ + FOR( i = 0; i < length; i++ ) + { + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + move32(); + } BREAK; case IVAS_FILTER_ORDER_4: + set_val_Word16( pIn_Out_e, sub( Q31, q_factor ), length ); /* biquad-1 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, q_factor ); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_0, pIn_Out_e ); /* biquad-2 */ - ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, q_factor ); + ivas_iir_2_filter_fx( filter_state, pIn_Out_fx, length, IVAS_FILTER_STAGE_1, pIn_Out_e ); + /* Scale pIn_Out_fx back to input Q */ + FOR( i = 0; i < length; i++ ) + { + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + move32(); + } BREAK; default: BREAK; @@ -295,54 +311,44 @@ static void ivas_iir_2_filter_fx( Word32 *pIn_Out_fx, const Word16 length, const Word16 stage, - Word16 q_factor ) + Word16 *pIn_Out_e ) { Word16 i, j; Word32 *pIn_fx = pIn_Out_fx; Word32 *pOut_fx = pIn_Out_fx; - Word16 pOut_e; Word32 tmp_pIn_buf_i_fx; + Word16 tmp_pIn_buf_i_e; Word32 L_tmp_prod, L_tmp; Word16 L_prod_e, L_tmp_e; - move16(); - move16(); - FOR( i = 0; i < length; i++ ) { tmp_pIn_buf_i_fx = pIn_fx[i]; move32(); + tmp_pIn_buf_i_e = pIn_Out_e[i]; + move16(); L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); - L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][0] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][0] ) ) - 31 ) + L_prod_e = add( pIn_Out_e[i], filter_state->num_e[stage][0] ); - pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pOut_e ); + pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); move32(); FOR( j = 1; j < filter_state->filt_len; j++ ) { L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); - L_prod_e = sub( 31, sub( q_factor, filter_state->num_e[stage][j] ) ); // 31 - ( ( q_factor + ( 31 - filter_state->num_e[stage][j] ) ) - 31 ) + L_prod_e = add( filter_state->num_e[stage][j], tmp_pIn_buf_i_e ); L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); - L_prod_e = add( pOut_e, filter_state->den_e[stage][j] ); // 31 - ( ( ( 31 - pOut_e ) + ( 31 - filter_state->den_e[stage][j] ) ) - 31 ); + L_prod_e = add( pIn_Out_e[i], filter_state->den_e[stage][j] ); filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); move32(); } - - /* Scaling pOut_fx to Q11 */ - pOut_fx[i] = L_shr_sat( pOut_fx[i], sub( sub( 31, q_factor ), pOut_e ) ); - move32(); - IF( pOut_fx[i] < 0 ) - { - pOut_fx[i] = L_add( pOut_fx[i], 1 ); - move32(); - } } } #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 2af3c52eb..b39aada25 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4399,12 +4399,14 @@ void reset_metadata_spatial( ); /*! r: number of bits written */ +#ifndef IVAS_FLOAT_FIXED void ivas_qmetadata_enc_sid_encode( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure*/ const int16_t ivas_format /* i : ivas format */ ); +#endif /*! r: number of bits read */ int16_t ivas_qmetadata_dec_decode( @@ -4535,6 +4537,16 @@ uint16_t quantize_direction( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 quantize_direction2D_fx( + Word32 phi, /* i : input azimuth value Q22 */ + const Word16 no_cw, /* i : number of bits */ + Word32 *phi_q, /* o : quantized azimuth value Q22 */ + UWord16 *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); +#endif + int16_t quantize_direction2D( float phi, /* i : input azimuth value */ const int16_t no_cw, /* i : number of bits */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d7a70af1b..291f1649a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3288,19 +3288,18 @@ void computeReferencePower_enc_fx( Word16 ref_power_w, /* i : use 0 if hodirac is enabled */ const Word16 nchan_ana /* i : number of analysis channels */ ); -void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - float *data_in_f[], /* i/o: Input / transport audio signals */ - Word32 *data_in[], /* i/o: Input / transport audio signals */ - Word16 q_data, /* i:Q0 Stores the q for data_in_f */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_transport, /* i : Number of transport channels */ - const int16_t nchan_ism, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - float *data_separated_object, /* o : Separated object audio signal */ - int16_t *idx_separated_object /* o : Index of the separated object */ +void ivas_omasa_enc_fx( + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + Word32 *data_in[], /* i/o: Input / transport audio signals */ + Word16 q_data, /* i:Q0 Stores the q for data_in_f */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_transport, /* i : Number of transport channels */ + const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + Word32 *data_separated_object_fx, /* o : Separated object audio signal */ + Word16 *idx_separated_object /* o : Index of the separated object */ ); void mctStereoIGF_enc_fx( @@ -3373,4 +3372,24 @@ void ivas_merge_masa_metadata_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ ); + +/*! r: number of bits written */ +void ivas_qmetadata_enc_sid_encode_fx( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ + const Word16 masa_sid_descriptor, /* i : description of MASA SID coding structure*/ + const Word16 ivas_format /* i : ivas format */ +); +void ivas_param_mc_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + Word32 *data_f_fx[], /* i/o: input/transport MC data Q11 */ + const Word16 input_frame /* i : input frame length */ +); +void ivas_merge_masa_transports_fx( + Word32 data_in_f1_fx[][L_FRAME48k], + Word32 *data_in_f2_fx[], + Word32 *data_out_f_fx[], + const Word16 input_frame, + const Word16 num_transport_channels ); #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 6722a87f2..b0f68be41 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -482,6 +482,8 @@ const Word32 dft_res_gains_q_fx[][2] = { { (Word32)( 0x7fff5800 ), (Word32)( 0x00cf398f ) }, }; + +// Q13 const Word16 McMASA_LFEGain_vectors_fx_q13[64] = { 3112, 2703, 1556, 1638, -1310, -1802, -2867, -2785, 4096, 4096, 4096, 4096, -6553, -3276, 8355, 819, @@ -493,6 +495,26 @@ const Word16 McMASA_LFEGain_vectors_fx_q13[64] = { -6553, -12943, 6717, 11632, -17530, 2129, 6881, 8355 }; +// Q25 +const Word32 McMASA_LFEGain_vectors_fx_q25[64] = { + 12750684, 11072963, 6375342, 6710886, /* 1st bit */ + -5368709, -7381975, -11744051, -11408507, + 16777216, 16777216, 16777216, 16777216, /* 2nd bit*/ + -26843546, -13421773, 34225521, 3355443, + -16777216, -16777216, -16777216, -16777216, /* 3rd bit */ + -18790482, -4026532, -26172457, 45634028, + -34225521, 39594230, -19126026, 11072963, + 24159191, -37916508, 32547799, -20803748, + -30534533, 31205622, 33554432, -36909875, /* 4th bit*/ + 58049167, -7717519, -26172457, -28185723, + 31876710, -53687091, -11408507, 31205622, + 29192356, 15770583, -63753421, 17448305, + 22481469, 47647293, -32547799, -41607496, + 27850179, 19461571, 20468204, -68451041, + -26843546, -53016003, 27514634, 47647293, + -71806484, 8724152, 28185723, 34225521 +}; + /* This lookup table is calculated from, and therefore depends on the following macros: diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 93a59b83c..4cf61f9ae 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -58,6 +58,7 @@ extern const Word16 dft_trigo_32k_fx[STEREO_DFT_N_32k_ENC / 4 + 1]; extern const Word16 dft_trigo_48k_fx[STEREO_DFT_N_MAX_ENC / 4 + 1]; extern const Word16 gridEq_Table[NO_THETA16_MAX]; extern const Word16 McMASA_LFEGain_vectors_fx_q13[64]; +extern const Word32 McMASA_LFEGain_vectors_fx_q25[64]; extern const Word16 ivas_divde_255[256]; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 3c9e2ee74..4cb4168df 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -473,7 +473,7 @@ typedef struct ivas_masa_common_spatial_meta_struct float surround_coherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 diffuse_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 - Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q15 + Word16 surround_coherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q14 Word32 remainder_to_total_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 #endif float remainder_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; diff --git a/lib_com/options.h b/lib_com/options.h index 5add1e88e..17a04a6cb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -1,194 +1,194 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#ifndef OPTIONS_H -#define OPTIONS_H - -/* clang-format off */ - -/* ################### Start DEBUGGING switches ######################## */ - -#ifdef _MSC_VER -#pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ -#endif - -/*#define DEBUGGING*/ /* Allows debugging message to be printed out during runtime */ -#ifdef DEBUGGING -#define DEBUG_MODE_INFO /* define to output most important parameters to the subdirectory "res/" */ -#define DEBUG_MODE_INFO_TWEAK /* enable command line switch to specify subdirectory for debug info output inside "./res/" */ -/*#define DBG_WAV_WRITER*/ /* enable dbgwrite_wav() function for generating ".wav" files */ -#endif - -#define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ - -/*#define WMOPS*/ /* Activate complexity and memory counters */ -#ifdef WMOPS -/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ -/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ -#endif - -/* #################### End DEBUGGING switches ############################ */ - -/* ################### Start FIXES switches ########################### */ - -#define NON_BE_FIX_1048_THRESHOLD_COH_BASOP /* Nokia: Fix 1048 replace comparison with 0 with comparison to threshold, to align with BASOP*/ -#define NONBE_FIX_1054_NEGATIVE_LVQ_INDEX /* Nokia: issue 1054: Input to decode_comb in deindex_lvq_SHB should be positive */ -#define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ -#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ -#define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ -#define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ -#define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ -#define NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /* VA: Add fix point bit allocation for special GSC mode such that float and fixed point have the same final bit allocation */ -#define NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE /* VA: issue 1132: prevent division by extremely low energy value in SWB TBE */ -#define NON_BE_FIX_807_MASA_DTX_BRSW /* Nokia: adds fix to check existence of DTX encoder for secondary channel in TD mode */ -#define FIX_BASOP_812_NAN_COHSNR /* FhG: BASOP issue 812: fix nan values in sparse frames for cohSNR value in ITD estimation*/ -#define FIX_828_PORT_1152_FROM_FLT_REPO /* FhG: fix for issue 828 - fix uninitialized value used in BASOP */ -/* #################### End FIXES switches ############################ */ - -#define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ - - -/* ################### Start BE switches ################################# */ -/* only BE switches wrt selection floating point code */ - -/*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ - -#define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ -#define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ -#define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ -#define FIX_901_PARAMMC_DEAD_CODE /* FhG: issue 901: remove dead ParamMC code */ -#define IVAS_ENH32_CADENCE_CHANGES - -/* #################### End BE switches ################################## */ - - -/* #################### Start NON-BE switches ############################ */ -/* any switch which is non-be wrt selection floating point code */ -/* all switches in this category should start with "NONBE_" */ - -#define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */ -#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ -#define BE_FIX_832_ASAN_ERROR_EFAP_OSBA /* FhG: issue #832: fix ASAN error caused by re-allocating EFAP memories in OSBA*/ -#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */ -#define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ -#define NONBE_FIX_738_QUATERNION_SLERP_PRECISION /* Quaternion slerp changes*/ -#define IVAS_FLOAT_FIXED -#define IVAS_FLOAT_FIXED_CONVERSIONS /* Temporary macro to keep track of intermediate flt to fixed and fixed to flt conversions */ -#ifdef IVAS_FLOAT_FIXED -#define MSAN_FIX -#define FIX_818_COMPLEXITY_IMPROV /* Fix for issue 818 */ -#define FIX_805_VERIFICATION /* Fix for issue 805 */ -#define FIX_827_HIGH_MLD /* Fix for issue 827 */ -//#define HP20_FIX32_RECODING /* Improved hp20 filtering code */ -#endif -#define ISM_DISABLE -#define FIX_TMP_714 -#define BASOP_NOGLOB_TMP_715 -#define EVS_FUNC_MODIFIED -//#define EVS_FLOAT_ENC -#define FIX_667_DISABLE_INITIAL_PLC_SUPPRESSION -#define IVAS_CNST -#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused EVS parameters to remove warnings, these parameters will be used in IVAS */ - -#define MOD_BIT_ALLOC_ROM_TABLE /* Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/ -#define SIMPLIFY_CODE_BE // Simplify synthesis loop - -#define CR_2109_to_2112_cd0_ce0 /* This is related to the CRs include in the 26.444 package of 21-12. Concerns lead_deindexing and */ - -#define FIX_ISSUE_723_INFO_TCX_NOISE /*FhG: Issue 723: fix for IGF that introduces wrong noise filling behavion*/ - -#define FIX_QMETADATA_PENALTY /* Nokia: transform penalty calculation in qmetadata into integer operations */ - -#define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ -#define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ -#define NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL - -/* ##################### End NON-BE switches ########################### */ -#define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE -#define FIX_746 // proposed fix to solve low bit-rate frame boundaries issues -#define FIX_SATURATION_725 // Propose fix for saturation in AVQ -#define FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR /* Eri: Proposed fix for issue 737: scaling error in excitation memory after HQ->ACELP switch */ -#define FIX_736_BWE_SECT_C // Solves an issue where the BWE was disappearing, problem related to wrong scaling in ic-BWE -#define FIX_734_MISSING_SUBFR_LOW_RATE_ACELP -#define FIX_747_TDBWE_ENERGY_BURST -#define FIX_770_DISCONTINUITIES_SW_TCX2ACELP // Fix discontinuities when switching from TCX to ACELP -#define FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step was right shift by 2, which made the OVA wrong */ -#define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ -#define FIX_778_STEREO_BRATE_SWITCHING -#define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ -#define FIX_729_MISSING_RESCALING -#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ -#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ -#define FIX_800_PROPOSAL_HB_LPC_COEFFICIENT /* Proposal to fix wrong shape of TDBWE, #800 */ - -#define FIX_802__NON_BE_DECODING /* Fix possible difference float and fixed point when computing the GSC bit allocation */ -#define FIX_802_1137_1137_GSC_IVAS_FXFLT_DECODING /* VA: ISSUES 802 and 1137 Made sure that float and fixed point GCS bit allocation is the same during IVAS modes */ -#define FIX_810_PREVENT_UNECESSARY_SAT_IN_TC /* VA : Prevent an unnecessary saturation that can happen in TC, have a minimal impact on most cases. Significant improvement for the last segment of LTV when TC is triggered */ -#define FIX_826_PRECISION_LOST_AND_COMPL /* VA : Fix lost of precision that leads to unnecessary high noise floor and to some framing artifacts */ -#ifdef FIX_826_PRECISION_LOST_AND_COMPL -#define FIX_833_CORRECTION_to_826 /* VA : fix indexing error introduced in 826 */ -#endif -#define NONE_BE_FIX_816_LFE_PLC_FLOAT /* DLB: issue 816: reduce required precision to float for LFE-PLC*/ -#define FIX_844_Q_SYN_INIT /* VA : proposed fix to 844, initializing q_old_synth when switching to MDCT*/ -#define FIX_839_FB_CONTENT_SOMETIME_MISSING /* VA : Fix scaling error for FB TB BWE */ -#define FIX_846_TILT_BWE /* VA : Proposed fix to 846, to solve saturation */ -#define FIX_843_LOW_RATE_BWE /* VA : Proposed fix to 843 to solve mid band noise */ -#define FIX851_RANGE_DEC_PRECISION /* VA : 851 Proposed fix to keep precision during UL_div*/ -#define FX_834_OVFL_JBM_CROSSCORR /* FhG: Proposed fix to 834, allow overflows in calculation */ - - -#define FIX_854_HILBERT_SCALING /* VA: reduce lost of precision due to unnecessary scaling, reduce a lot the 2 kHz tone */ -#define FIX_856_EXTRACT_L /* VA: Fix undesirable wrap-around */ -#define FIX_835_PARAMMC_BUFFER_VALUES /* FhG: issue 835: wide range of buffer values for cx in ParamMC */ - -#define FIX_860_FER_CRASH /* VA: fix crash issues caused by saturation within shl */ -#define FIX_961_CRASH_DIV_L /* VA: fix to potential crash in div_l when index is <= 0 */ - -#define FIX_869_WRONG_UVGAIN_STEP /* VA: Fix wrong decoding of uv gain quantizer for td-stereo*/ - -#define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ -#define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ -#define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ -#define FIX_879_DIFF_CONCEAL_PATH /* FhG: Fix for issue 879 and different concelalment paths that led to crash */ -#define FIX_907_MEM_UPDATE_ISSUE /* VA: fix for 907, multiples issues surrounding mem_syn_r and update of mem_syn2 when FS is changing */ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 + ====================================================================================*/ + +#ifndef OPTIONS_H +#define OPTIONS_H + +/* clang-format off */ + +/* ################### Start DEBUGGING switches ######################## */ + +#ifdef _MSC_VER +#pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ +#endif + +/*#define DEBUGGING*/ /* Allows debugging message to be printed out during runtime */ +#ifdef DEBUGGING +#define DEBUG_MODE_INFO /* define to output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO_TWEAK /* enable command line switch to specify subdirectory for debug info output inside "./res/" */ +/*#define DBG_WAV_WRITER*/ /* enable dbgwrite_wav() function for generating ".wav" files */ +#endif + +#define SUPPORT_JBM_TRACEFILE /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ + +/*#define WMOPS*/ /* Activate complexity and memory counters */ +#ifdef WMOPS +/*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ +/*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ +#endif + +/* #################### End DEBUGGING switches ############################ */ + +/* ################### Start FIXES switches ########################### */ + +#define NON_BE_FIX_1048_THRESHOLD_COH_BASOP /* Nokia: Fix 1048 replace comparison with 0 with comparison to threshold, to align with BASOP*/ +#define NONBE_FIX_1054_NEGATIVE_LVQ_INDEX /* Nokia: issue 1054: Input to decode_comb in deindex_lvq_SHB should be positive */ +#define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ +#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ +#define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ +#define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ +#define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ +#define NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /* VA: Add fix point bit allocation for special GSC mode such that float and fixed point have the same final bit allocation */ +#define NONBE_FIX_1132_THRESHOLD_POW_IN_SWB_TBE /* VA: issue 1132: prevent division by extremely low energy value in SWB TBE */ +#define NON_BE_FIX_807_MASA_DTX_BRSW /* Nokia: adds fix to check existence of DTX encoder for secondary channel in TD mode */ +#define FIX_BASOP_812_NAN_COHSNR /* FhG: BASOP issue 812: fix nan values in sparse frames for cohSNR value in ITD estimation*/ +#define FIX_828_PORT_1152_FROM_FLT_REPO /* FhG: fix for issue 828 - fix uninitialized value used in BASOP */ +/* #################### End FIXES switches ############################ */ + +#define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ + + +/* ################### Start BE switches ################################# */ +/* only BE switches wrt selection floating point code */ + +/*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ + +#define FIX_854_ARRAY_SIZE_MISMATCH /* VA: issue 854: correct the mismatch between definition and declaration of `ivas_core_dec() */ +#define FIX_785_REMOVE_DEAD_CODE /* VA: issue 785: remove dead code */ +#define FIX_852_FIX_HANDLE_DEREF /* VA: issue 852: Fix missing handle dereferencing of hIsmMetadaData in ivas_ism_metadata_close() */ +#define FIX_901_PARAMMC_DEAD_CODE /* FhG: issue 901: remove dead ParamMC code */ +#define IVAS_ENH32_CADENCE_CHANGES + +/* #################### End BE switches ################################## */ + + +/* #################### Start NON-BE switches ############################ */ +/* any switch which is non-be wrt selection floating point code */ +/* all switches in this category should start with "NONBE_" */ + +#define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */ +#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ +#define BE_FIX_832_ASAN_ERROR_EFAP_OSBA /* FhG: issue #832: fix ASAN error caused by re-allocating EFAP memories in OSBA*/ +#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */ +#define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ +#define NONBE_FIX_738_QUATERNION_SLERP_PRECISION /* Quaternion slerp changes*/ +#define IVAS_FLOAT_FIXED +#define IVAS_FLOAT_FIXED_CONVERSIONS /* Temporary macro to keep track of intermediate flt to fixed and fixed to flt conversions */ +#ifdef IVAS_FLOAT_FIXED +#define MSAN_FIX +#define FIX_818_COMPLEXITY_IMPROV /* Fix for issue 818 */ +#define FIX_805_VERIFICATION /* Fix for issue 805 */ +#define FIX_827_HIGH_MLD /* Fix for issue 827 */ +//#define HP20_FIX32_RECODING /* Improved hp20 filtering code */ +#endif +#define ISM_DISABLE +#define FIX_TMP_714 +#define BASOP_NOGLOB_TMP_715 +#define EVS_FUNC_MODIFIED +//#define EVS_FLOAT_ENC +#define FIX_667_DISABLE_INITIAL_PLC_SUPPRESSION +#define IVAS_CNST +#define REMOVE_IVAS_UNUSED_PARAMETERS_WARNING /*temporary operation on unused EVS parameters to remove warnings, these parameters will be used in IVAS */ + +#define MOD_BIT_ALLOC_ROM_TABLE /* Just to highlight modification in bit allocation table and to ensure these modifications doesn't affect EVS modes*/ +#define SIMPLIFY_CODE_BE // Simplify synthesis loop + +#define CR_2109_to_2112_cd0_ce0 /* This is related to the CRs include in the 26.444 package of 21-12. Concerns lead_deindexing and */ + +#define FIX_ISSUE_723_INFO_TCX_NOISE /*FhG: Issue 723: fix for IGF that introduces wrong noise filling behavion*/ + +#define FIX_QMETADATA_PENALTY /* Nokia: transform penalty calculation in qmetadata into integer operations */ + +#define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ +#define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ +#define NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL + +/* ##################### End NON-BE switches ########################### */ +#define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE +#define FIX_746 // proposed fix to solve low bit-rate frame boundaries issues +#define FIX_SATURATION_725 // Propose fix for saturation in AVQ +#define FIX_737_HQ_ACELP_SWITCH_SCALING_ERROR /* Eri: Proposed fix for issue 737: scaling error in excitation memory after HQ->ACELP switch */ +#define FIX_736_BWE_SECT_C // Solves an issue where the BWE was disappearing, problem related to wrong scaling in ic-BWE +#define FIX_734_MISSING_SUBFR_LOW_RATE_ACELP +#define FIX_747_TDBWE_ENERGY_BURST +#define FIX_770_DISCONTINUITIES_SW_TCX2ACELP // Fix discontinuities when switching from TCX to ACELP +#define FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step was right shift by 2, which made the OVA wrong */ +#define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ +#define FIX_778_STEREO_BRATE_SWITCHING +#define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ +#define FIX_729_MISSING_RESCALING +#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ +#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ +#define FIX_800_PROPOSAL_HB_LPC_COEFFICIENT /* Proposal to fix wrong shape of TDBWE, #800 */ + +#define FIX_802__NON_BE_DECODING /* Fix possible difference float and fixed point when computing the GSC bit allocation */ +#define FIX_802_1137_1137_GSC_IVAS_FXFLT_DECODING /* VA: ISSUES 802 and 1137 Made sure that float and fixed point GCS bit allocation is the same during IVAS modes */ +#define FIX_810_PREVENT_UNECESSARY_SAT_IN_TC /* VA : Prevent an unnecessary saturation that can happen in TC, have a minimal impact on most cases. Significant improvement for the last segment of LTV when TC is triggered */ +#define FIX_826_PRECISION_LOST_AND_COMPL /* VA : Fix lost of precision that leads to unnecessary high noise floor and to some framing artifacts */ +#ifdef FIX_826_PRECISION_LOST_AND_COMPL +#define FIX_833_CORRECTION_to_826 /* VA : fix indexing error introduced in 826 */ +#endif +#define NONE_BE_FIX_816_LFE_PLC_FLOAT /* DLB: issue 816: reduce required precision to float for LFE-PLC*/ +#define FIX_844_Q_SYN_INIT /* VA : proposed fix to 844, initializing q_old_synth when switching to MDCT*/ +#define FIX_839_FB_CONTENT_SOMETIME_MISSING /* VA : Fix scaling error for FB TB BWE */ +#define FIX_846_TILT_BWE /* VA : Proposed fix to 846, to solve saturation */ +#define FIX_843_LOW_RATE_BWE /* VA : Proposed fix to 843 to solve mid band noise */ +#define FIX851_RANGE_DEC_PRECISION /* VA : 851 Proposed fix to keep precision during UL_div*/ +#define FX_834_OVFL_JBM_CROSSCORR /* FhG: Proposed fix to 834, allow overflows in calculation */ + + +#define FIX_854_HILBERT_SCALING /* VA: reduce lost of precision due to unnecessary scaling, reduce a lot the 2 kHz tone */ +#define FIX_856_EXTRACT_L /* VA: Fix undesirable wrap-around */ +#define FIX_835_PARAMMC_BUFFER_VALUES /* FhG: issue 835: wide range of buffer values for cx in ParamMC */ + +#define FIX_860_FER_CRASH /* VA: fix crash issues caused by saturation within shl */ +#define FIX_961_CRASH_DIV_L /* VA: fix to potential crash in div_l when index is <= 0 */ + +#define FIX_869_WRONG_UVGAIN_STEP /* VA: Fix wrong decoding of uv gain quantizer for td-stereo*/ + +#define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ +#define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ +#define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ +#define FIX_879_DIFF_CONCEAL_PATH /* FhG: Fix for issue 879 and different concelalment paths that led to crash */ +#define FIX_907_MEM_UPDATE_ISSUE /* VA: fix for 907, multiples issues surrounding mem_syn_r and update of mem_syn2 when FS is changing */ #define FIX_918_WRONG_SCALING_ON_MODE_SWITCHING /* VA: Fix wrong scaling of secondary channel when switching from stereo DFT to TD */ - -/* ################## End DEVELOPMENT switches ######################### */ - -/* clang-format on */ -#define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO - -#endif + +/* ################## End DEVELOPMENT switches ######################### */ + +/* clang-format on */ +#define NONBE_FIX_1010_STEREO_CNG_DIV_BY_ZERO + +#endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index e87e55193..24e5ae866 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6028,23 +6028,22 @@ void CNG_dec_fx( Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ - , + Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ Word32 *q_env ); void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); void swb_CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ); @@ -8198,11 +8197,11 @@ ivas_error ppp_quarter_decoder_fx( // core_dec_init_fx.c void open_decoder_LPD_fx( Decoder_State *st, - const Word32 total_brate, + const Word32 total_brate, /* Q0 */ #ifdef NEW_IVAS_OPEN_DEC const Word32 last_total_brate, #endif - const Word16 bwidth + const Word16 bwidth /* Q0 */ #ifdef NEW_IVAS_OPEN_DEC , const Word16 is_mct, /* i : MCT mode flag */ @@ -8214,13 +8213,13 @@ void open_decoder_LPD_fx( ); #ifdef IVAS_FLOAT_FIXED void open_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 last_total_brate, /* i : last total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 last_element_mode, /* i : last element mode */ - const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -8240,12 +8239,12 @@ void acelp_plc_mdct_transition_fx( void cldfb_reset_memory_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ); void tcxltp_dec_init_fx( - TCX_LTP_DEC_HANDLE hTcxLtpDec, - const Word16 ini_frame, - const Word16 last_codec_mode, - const Word16 element_mode, - const Word16 pit_max, - const Word32 sr_core ); + TCX_LTP_DEC_HANDLE hTcxLtpDec, /* Q0 */ + const Word16 ini_frame, /* Q0 */ + const Word16 last_codec_mode, /* Q0 */ + const Word16 element_mode, /* Q0 */ + const Word16 pit_max, /* Q0 */ + const Word32 sr_core ); /* Q0 */ // swb_bwe_dec_hr_fx.c Word16 swb_bwe_dec_hr_fx( @@ -9062,14 +9061,20 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( ); // core_dec_reconf_fx.c -void reconfig_decoder_LPD_fx( Decoder_State *st, Word16 bits_frame, Word16 bandwidth_mode, Word32 bitrate, Word16 L_frame_old ); +void reconfig_decoder_LPD_fx( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 bits_frame, /* i : bit budget Q0*/ + Word16 bwidth, /* i : audio bandwidth Q0*/ + Word32 total_brate, /* i : total bitrate Q0*/ + Word16 L_frame_old /* i : frame length Q0*/ +); #ifdef IVAS_FLOAT_FIXED void reconfig_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bits_frame, /* i : bit budget */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 L_frame_old /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bits_frame, /* i : bit budget Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 L_frame_old /* i : frame length Q0*/ ); #endif // IVAS_FLOAT_FIXED @@ -10015,10 +10020,10 @@ void Vr_subt( #ifdef IVAS_FLOAT_FIXED Word16 vquant_ivas_fx( /* o: index of the winning codevector */ - Word16 x[], /* i: vector to quantize Q13 */ - const Word16 x_mean[], /* i: vector mean to subtract (0 if none) Q13 */ - Word16 xq[], /* o: quantized vector Q13 */ - const Word16 cb[], /* i: codebook Q13 */ + Word32 x[], /* i: vector to quantize Q25 */ + const Word32 x_mean[], /* i: vector mean to subtract (0 if none) Q25 */ + Word32 xq[], /* o: quantized vector Q25 */ + const Word32 cb[], /* i: codebook Q25 */ const Word16 dim, /* i: dimension of codebook vectors */ const Word16 cbsize /* i: codebook size */ ); diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 50869066c..e1e609a04 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -130,8 +130,8 @@ typedef struct float formant_enh_num_flt; float formant_enh_den_flt; - Word16 formant_enh_num; - Word16 formant_enh_den; + Word16 formant_enh_num; /* Q15 */ + Word16 formant_enh_den; /* Q15 */ int16_t bpf_mode; diff --git a/lib_com/tec_com_flt.c b/lib_com/tec_com_flt.c index 3d64b6048..f19893979 100644 --- a/lib_com/tec_com_flt.c +++ b/lib_com/tec_com_flt.c @@ -43,6 +43,7 @@ #include "stat_dec.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * Local constants *-------------------------------------------------------------------*/ @@ -269,7 +270,6 @@ static float calcCorrelationCoefficient2( } -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * resetTecDec() * @@ -285,7 +285,6 @@ void resetTecDec( return; } -#endif /*------------------------------------------------------------------- @@ -932,3 +931,4 @@ void tecEnc_TBE( return; } +#endif diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 9d3681b6e..140e064a7 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -1681,21 +1681,16 @@ void Vr_subt( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED Word16 vquant_ivas_fx( /* o: index of the winning codevector */ - Word16 x[], /* i: vector to quantize Q13 */ - const Word16 x_mean[], /* i: vector mean to subtract (0 if none) Q13 */ - Word16 xq[], /* o: quantized vector Q13 */ - const Word16 cb[], /* i: codebook Q13 */ + Word32 x[], /* i: vector to quantize Q25 */ + const Word32 x_mean[], /* i: vector mean to subtract (0 if none) Q25 */ + Word32 xq[], /* o: quantized vector Q25 */ + const Word32 cb[], /* i: codebook Q25 */ const Word16 dim, /* i: dimension of codebook vectors */ const Word16 cbsize /* i: codebook size */ ) { - Word16 tmp; Word16 c, d, idx, j; - Word32 L_dist, /*L_tmp,*/ L_mindist; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif + Word32 L_dist, L_tmp, L_mindist; idx = 0; move16(); @@ -1706,8 +1701,8 @@ Word16 vquant_ivas_fx( /* o: index of the winning codevec FOR( d = 0; d < dim; d++ ) { /*x[d] -= x_mean[d]; */ - x[d] = sub( x[d], x_mean[d] ); - move16(); /*Qx */ + x[d] = L_sub( x[d], x_mean[d] ); + move32(); /*Qx */ } } j = 0; @@ -1720,20 +1715,15 @@ Word16 vquant_ivas_fx( /* o: index of the winning codevec FOR( d = 0; d < dim; d++ ) { /*tmp = x[d] - cb[j++];*/ -#ifdef BASOP_NOGLOB - tmp = sub_o( x[d], cb[j++], &Overflow ); /*Qx */ - L_dist = L_mac0_o( L_dist, tmp, tmp, &Overflow ); -#else - tmp = sub( x[d], cb[j++] ); /*Qx */ - L_dist = L_mac0( L_dist, tmp, tmp ); -#endif + L_tmp = L_sub( x[d], cb[j++] ); // Q25 + L_dist = L_add( L_dist, Mpy_32_32( L_tmp, L_tmp ) ); // (Q25, Q25) -> Q19 } - if ( LT_32( L_dist, L_mindist ) ) + if ( LT_32( L_dist, L_mindist ) ) // Q19 { idx = c; move16(); } - L_mindist = L_min( L_mindist, L_dist ); + L_mindist = L_min( L_mindist, L_dist ); // Q19 } IF( xq == 0 ) { @@ -1744,16 +1734,16 @@ Word16 vquant_ivas_fx( /* o: index of the winning codevec j = i_mult2( idx, dim ); FOR( d = 0; d < dim; d++ ) { - xq[d] = cb[j++]; - move16(); + xq[d] = cb[j++]; // Q25 + move32(); } IF( x_mean != 0 ) { FOR( d = 0; d < dim; d++ ) { /*xq[d] += x_mean[d]; */ - xq[d] = add( xq[d], x_mean[d] ); - move16(); + xq[d] = L_add( xq[d], x_mean[d] ); // Q25 + move32(); } } diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 9919e1f21..d17bf1966 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -38,7 +38,7 @@ void CNG_dec_fx( Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID */ + Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ , Word32 *q_env ) { @@ -107,8 +107,8 @@ void CNG_dec_fx( IF( ( shr( enr_new, 14 ) > 0 ) ) { /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ } } ELSE @@ -127,22 +127,22 @@ void CNG_dec_fx( IF( shr( enr_new, 14 ) > 0 ) { /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ } } } ELSE { /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); - Copy( st_fx->lsf_old_fx, lsf_new, M ); + Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ + Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ } /* Initialize the CNG spectral envelope in case of the very first CNG frame */ IF( st_fx->first_CNG == 0 ) { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -154,11 +154,11 @@ void CNG_dec_fx( test(); IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { - istep = ISTEP_AMR_WB_SID_FX; + istep = ISTEP_AMR_WB_SID_FX; /* Q15 */ move16(); if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - istep = ISTEP_SID_FX; + istep = ISTEP_SID_FX; /* Q15 */ move16(); } @@ -182,14 +182,14 @@ void CNG_dec_fx( { tmp1 = add( hTdCngDec->old_enr_index, 40 ); } - IF( GT_16( L_enr_index, tmp1 ) && GE_16( hTdCngDec->old_enr_index, 0 ) ) /* Likely bit error and not startup */ + IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ { L_enr_index = tmp1; move16(); - L_enr_index = s_min( L_enr_index, 127 ); + L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */ IF( st_fx->Opt_AMR_WB ) { - L_enr_index = s_min( L_enr_index, 63 ); + L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */ } } @@ -301,7 +301,7 @@ void CNG_dec_fx( } /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX */ + burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/ hTdCngDec->act_cnt = 0; move16(); s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); @@ -312,7 +312,7 @@ void CNG_dec_fx( FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { - hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); + hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */ move16(); if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { @@ -327,14 +327,14 @@ void CNG_dec_fx( IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); } /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), &( hTdCngDec->ho_lsp_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, M )] ), M ); - Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); + Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */ + Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */ hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); move32(); - Copy32( &( hTdCngDec->ho_env_circ_fx[i_mult( s_ptr, NUM_ENV_CNG )] ), &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); + Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */ hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); move16(); @@ -361,7 +361,7 @@ void CNG_dec_fx( test(); test(); - IF( ( GT_32( L_tmp1, 0 ) && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); move16(); @@ -378,12 +378,12 @@ void CNG_dec_fx( /* Use average of energies below last energy */ ptr = hTdCngDec->ho_hist_ptr; move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )] ), tmp, M ); + Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */ m1 = 0; move16(); IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) { - Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } @@ -396,10 +396,10 @@ void CNG_dec_fx( move16(); FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) { - ptr = sub( ptr, 1 ); + ptr--; if ( ptr < 0 ) { - ptr = sub( HO_HIST_SIZE, 1 ); + ptr = HO_HIST_SIZE - 1; move16(); } @@ -414,13 +414,13 @@ void CNG_dec_fx( /*weights += W_DTX_HO[k];*/ weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )], &tmp[i_mult( m, M )], M ); + Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */ IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) { - Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], &tmp_env[i_mult( m1, NUM_ENV_CNG )], NUM_ENV_CNG ); - m1 = add( m1, 1 ); + Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */ + m1++; } - m = add( m, 1 ); + m++; } } @@ -439,19 +439,19 @@ void CNG_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[( M - 1 )], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } ELSE { - lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_16k_FX ); + lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); ftmp_fx = 1205; - move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[sub( M, 1 )], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ @@ -487,7 +487,7 @@ void CNG_dec_fx( IF( EQ_16( m, 1 ) ) { - Copy( tmp, lsp_tmp, M ); + Copy( tmp, lsp_tmp, M ); /* Qx */ } ELSE IF( LT_16( m, 4 ) ) { @@ -497,10 +497,10 @@ void CNG_dec_fx( move32(); FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); } - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ) ); + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ @@ -515,13 +515,13 @@ void CNG_dec_fx( move32(); FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); } - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ), L_deposit_l( tmp[add( i_mult( max_idx[1], M ), i )] ) ) ); /*Q15*/ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ move16(); } } @@ -546,7 +546,7 @@ void CNG_dec_fx( } test(); - IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) + IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */ { FOR( i = 0; i < M; i++ ) { @@ -559,7 +559,7 @@ void CNG_dec_fx( FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); + st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ move16(); } } @@ -582,7 +582,7 @@ void CNG_dec_fx( IF( EQ_16( m1, 1 ) ) { #ifdef BASOP_NOGLOB - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ #else L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif @@ -590,23 +590,23 @@ void CNG_dec_fx( ELSE { tmp1 = div_s( 1, m1 ); - L_tmp = Mult_32_16( L_tmp, tmp1 ); + L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */ #ifdef BASOP_NOGLOB - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); + L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ #else L_tmp = L_sub( L_tmp, L_add( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); #endif } - env[i] = L_tmp; + env[i] = L_tmp; /* Q6 */ move32(); } - Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); + Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ } } ELSE { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ + Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ } } @@ -622,7 +622,7 @@ void CNG_dec_fx( #endif { /* update the pointer to circular buffer of old LSP vectors */ - hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); + hTdCngDec->ho_hist_ptr++; move16(); if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { @@ -631,10 +631,10 @@ void CNG_dec_fx( } /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); + Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */ /* update the hangover energy buffer */ - hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; + hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */ move32(); test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) ) @@ -670,15 +670,15 @@ void CNG_dec_fx( env[i] = L_add( env[i], L_tmp ); /* Q6 */ move32(); } - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ move32(); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */ } ELSE IF( ( *sid_bw != 0 ) ) { - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); + hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ move32(); - hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); + hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */ move32(); } @@ -701,7 +701,7 @@ void CNG_dec_fx( } } - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); @@ -724,7 +724,7 @@ void CNG_dec_fx( tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ { - Copy( Aq, &Aq[i_mult( i, add( M, 1 ) )], add( M, 1 ) ); + Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */ } return; @@ -739,9 +739,9 @@ void CNG_dec_fx( #ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID Q0*/ , const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) @@ -780,11 +780,10 @@ void swb_CNG_dec_fx( #ifdef IVAS_FLOAT_FIXED void swb_CNG_dec_ivas_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - , - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { test(); @@ -826,11 +825,10 @@ void swb_CNG_dec_ivas_fx( #ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const Word16 sid_bw /* i : 0-NB/WB, 1-SWB SID */ - , - const Word16 Qsyn /* i : Q value of ACELP core synthesis */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ + const Word16 Qsyn /* i : Q value of ACELP core synthesis */ ) { Word16 i; @@ -872,7 +870,7 @@ static void shb_CNG_decod_fx( idx_ener_fx = -15; move16(); } - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { /* de-quantization of SHB CNG parameters */ L_tmp = L_mult( idx_ener_fx, 27400 ); /*Q14 */ @@ -972,7 +970,7 @@ static void shb_CNG_decod_fx( } } - gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /*8 */ + gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /* Q8 */ if ( GT_16( gain_fx, 15 ) ) { gain_fx = 15; @@ -982,7 +980,7 @@ static void shb_CNG_decod_fx( test(); IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st_fx->last_core_brate, SID_2k40 ) ) { - st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, step_fx ); + st_fx->shb_cng_ener_fx = add( st_fx->shb_cng_ener_fx, step_fx ); /* Q8 */ move16(); } ELSE @@ -1090,13 +1088,13 @@ static void shb_CNG_decod_fx( /* rescale the Hilbert memories to Q0 */ FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2 ); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st_fx->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ move32(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2 ); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st_fx->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ move16(); } } @@ -1118,10 +1116,10 @@ static void shb_CNG_decod_fx( #ifdef IVAS_FLOAT_FIXED static void shb_CNG_decod_ivas_fx( - Decoder_State *st, /* i/o: State structure */ - const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz */ - Word16 *shb_synth_fx, /* o : high-band CNG synthesis */ - const int16_t sid_bw, /* i : 0-NB/WB, 1-SWB SID */ + Decoder_State *st, /* i/o: State structure */ + const Word16 *synth_fx, /* i : ACELP core synthesis at 32kHz Qsyn*/ + Word16 *shb_synth_fx, /* o : high-band CNG synthesis Qx*/ + const Word16 sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0*/ const Word16 Qsyn ) { Word16 i; @@ -1151,14 +1149,14 @@ static void shb_CNG_decod_ivas_fx( allow_cn_step_fx = 0; move16(); - IF( EQ_16( st->bfi, 0 ) ) + IF( st->bfi == 0 ) { test(); IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { idx_ener = get_next_indice_fx( st, 4 ); - IF( EQ_16( idx_ener, 0 ) ) + IF( idx_ener == 0 ) { idx_ener = -15; move16(); @@ -1225,7 +1223,7 @@ static void shb_CNG_decod_ivas_fx( st->hTdCngDec->wb_cng_ener_fx_32 = wb_ener32_fx; move32(); /*Q11 */ } - if ( GT_32( L_abs( L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) + if ( GT_32( L_abs( L_sub( wb_ener32_fx, st->hTdCngDec->wb_cng_ener_fx_32 ) ), 24576 ) ) /* 12.0f in Q11 */ { allow_cn_step_fx = 1; move16(); @@ -1247,12 +1245,12 @@ static void shb_CNG_decod_ivas_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) { - st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; + st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; /* Q11 */ move32(); if ( !st->first_CNG ) { - st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; + st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; /* Q11 */ move32(); } } @@ -1267,7 +1265,7 @@ static void shb_CNG_decod_ivas_fx( test(); IF( EQ_16( allow_cn_step_fx, 1 ) || GT_32( st->last_core_brate, SID_2k40 ) ) { - st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, step_fx ); + st->hTdCngDec->shb_cng_ener_fx_32 = L_add( st->hTdCngDec->shb_cng_ener_fx_32, step_fx ); /* Q11 */ move32(); } ELSE @@ -1375,13 +1373,13 @@ static void shb_CNG_decod_ivas_fx( /* rescale the Hilbert memories to Q0 */ FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2 ); + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shr( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], st->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ move32(); } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2 ); + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], st->prev_Q_bwe_syn2 ); /* st_fx->prev_Q_bwe_syn2 */ move16(); } } @@ -1392,7 +1390,7 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); + Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); /* Qx - 3 */ ResetSHBbuffer_Dec_fx( st ); return; } @@ -1421,7 +1419,7 @@ void td_cng_dec_init_fx( move16(); hTdCngDec->old_enr_index = -1; move16(); - hTdCngDec->Enew_fx = L_deposit_l( 0 ); + hTdCngDec->Enew_fx = L_deposit_l( 0 ); /* Q6*/ move16(); hTdCngDec->last_allow_cn_step = 0; move16(); @@ -1521,7 +1519,7 @@ void td_cng_dec_init_ivas_fx( move16(); hTdCngDec->shb_cng_ener_fx_32 = -12329; // -6.02 in Q(11) move32(); - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { set16_fx( hTdCngDec->shb_lpcCNG_fx, 0, LPC_SHB_ORDER + 1 ); hTdCngDec->shb_lpcCNG_fx[0] = 32767; // 1 in Q(15) @@ -1573,15 +1571,15 @@ void td_cng_dec_init_ivas_fx( { IF( st->element_mode != EVS_MONO ) { - hTdCngDec->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i]; + hTdCngDec->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i]; /* Q14 */ move16(); } ELSE { - hTdCngDec->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + hTdCngDec->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; /* Q14 */ move16(); } - hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i]; + hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i]; /* Q14 */ move16(); } diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 3fc9f7203..51416a0ae 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -21,11 +21,11 @@ #ifdef IVAS_FLOAT_FIXED void open_decoder_LPD_fx( Decoder_State *st, - const Word32 total_brate, + const Word32 total_brate, /* Q0 */ #ifdef NEW_IVAS_OPEN_DEC const Word32 last_total_brate, #endif - const Word16 bwidth + const Word16 bwidth /* Q0 */ #ifdef NEW_IVAS_OPEN_DEC , const Word16 is_mct, /* i : MCT mode flag */ @@ -122,8 +122,8 @@ void open_decoder_LPD_fx( test(); test(); - IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || + IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; @@ -160,10 +160,10 @@ void open_decoder_LPD_fx( #if 0 PMT("Fixed point to be verified here") #endif - i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); - hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); /* Q6 */ + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */ move16(); - hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */ move16(); } } @@ -173,10 +173,10 @@ void open_decoder_LPD_fx( move16(); IF( hTcxDec != NULL ) { - i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); - hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /* Q6 */ + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */ move16(); - hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */ move16(); } } @@ -238,10 +238,10 @@ void open_decoder_LPD_fx( move16(); IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */ hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */ } /*TCX config*/ @@ -259,15 +259,15 @@ void open_decoder_LPD_fx( } /* TCX Offset */ - st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); + st->hTcxCfg->tcx_offset = shr( st->hTcxCfg->tcx_mdct_window_delay, 1 ); /* Q0 */ move16(); - st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); + st->hTcxCfg->tcx_offsetFB = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 ); /* Q0 */ move16(); /* Initialize FAC */ - st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); + st->hTcxCfg->lfacNext = sub( st->hTcxCfg->tcx_offset, shr( st->L_frame, 2 ) ); /* Q0 */ move16(); - st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxDec->L_frameTCX, 2 ) ); + st->hTcxCfg->lfacNextFB = sub( st->hTcxCfg->tcx_offsetFB, shr( hTcxDec->L_frameTCX, 2 ) ); /* Q0 */ move16(); /* set number of coded lines */ @@ -361,31 +361,31 @@ void open_decoder_LPD_fx( move16(); IF( hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); + set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */ - set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); - set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl_TDAC */ + set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec-> Q_syn_OverlFB */ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */ - set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); + set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /* hTcxDec->Q_syn_Overl */ - set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */ hTcxDec->q_old_synth = 0; move16(); - set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); + set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); /* hTcxDec->q_synth_history_fx */ hTcxDec->q_synth_history_fx = 0; move16(); } - set16_fx( st->syn, 0, add( M, 1 ) ); + set16_fx( st->syn, 0, add( M, 1 ) ); /* Qx */ - set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */ mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ move16(); - st->con_tcx = 0; + st->con_tcx = 0; /* Q0 */ move16(); } ELSE @@ -395,15 +395,15 @@ void open_decoder_LPD_fx( test(); IF( st->hTcxDec != NULL && ( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_codec_mode, MODE1 ) ) ) ) { - set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */ hTcxDec->q_old_synth = 0; move16(); } /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ - mem_syn_r_size_old = shr( st->last_L_frame, 4 ); - mem_syn_r_size_new = shr( st->L_frame, 4 ); + mem_syn_r_size_old = shr( st->last_L_frame, 4 ); /* Q0 */ + mem_syn_r_size_new = shr( st->L_frame, 4 ); /* Q0 */ /*Reset LPC mem*/ test(); @@ -411,23 +411,24 @@ void open_decoder_LPD_fx( IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) ) { /*LPC quant. mem*/ - set16_fx( st->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* (Qx2.56) */ IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* (Qx2.56) */ } } /*Codec switching*/ - IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) + test(); + IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); - set16_fx( st->syn, 0, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ + set16_fx( st->syn, 0, M ); /* Q_syn */ } IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { @@ -454,7 +455,7 @@ void open_decoder_LPD_fx( PWord16 const *w; Word16 W1, W2, nz, delay_comp; - W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; + W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ @@ -464,34 +465,34 @@ void open_decoder_LPD_fx( delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ move16(); - Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); + Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* hHQ_core->Q_fer_samples*/ lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ hHQ_core->Q_old_wtda = -1; move16(); - set16_fx( hHQ_core->old_out_fx, 0, nz ); + set16_fx( hHQ_core->old_out_fx, 0, nz ); /* exp(exp_old_out) */ Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/ FOR( i = 0; i < W2; i++ ) { - hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); + hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); + hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - ( 1 + ( i - W2 ) )].v.im, w[W2 - ( 1 + ( i - W2 ) )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */ move16(); } set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz ); lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); - Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); + Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* exp(exp_old_out) */ nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); move16(); - Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); + Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* hHQ_core->q_old_outLB_fx */ hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; move16(); } @@ -531,26 +532,26 @@ void open_decoder_LPD_fx( st->tilt_code_fx = TILT_CODE; move16(); move16(); - set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); - set16_fx( st->syn, 0, 1 + M ); - set16_fx( st->mem_syn2_fx, 0, M ); + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */ + set16_fx( st->syn, 0, 1 + M ); /* Q_syn */ + set16_fx( st->mem_syn2_fx, 0, M ); /* Q_syn */ /*OLA -> zero */ IF( st->hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_old_syn_Overl */ + set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDAC */ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDACFB */ + set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl */ #if 0 PMT("to be moved to reset_tcx_overl_buf") #endif } IF( st->hTcxCfg != NULL ) { - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* exp(exp_old_out) */ - st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ /* Q0 */ st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); move16(); @@ -558,7 +559,7 @@ void open_decoder_LPD_fx( /*OLA for MDCT-LB always reset in codec switching cases*/ IF( st->hHQ_core != NULL ) { - set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); + set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* hHQ_core->q_old_outLB_fx */ } st->last_core_bfi = TCX_20_CORE; move16(); @@ -600,8 +601,8 @@ void open_decoder_LPD_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.5 */ IF( !st->last_con_tcx ) { @@ -621,14 +622,14 @@ void open_decoder_LPD_fx( move16(); IF( !st->last_con_tcx ) { - set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */ } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */ /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); /* Q_mem_syn_r */ + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Q_mem_syn_r */ /*Untouched memories : st->syn */ } @@ -647,9 +648,9 @@ void open_decoder_LPD_fx( } IF( st->hTcxDec != NULL ) { - hTcxDec->old_synth_len = shl( st->L_frame, 1 ); + hTcxDec->old_synth_len = shl( st->L_frame, 1 ); /* Q0 */ move16(); - hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 ); + hTcxDec->old_synth_lenFB = shl( hTcxDec->L_frameTCX, 1 ); /* Q0 */ move16(); } /* bass pf reset */ @@ -679,7 +680,7 @@ void open_decoder_LPD_fx( set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); st->hPFstat->reset = 1; move16(); - st->hPFstat->gain_prec = 16384; + st->hPFstat->gain_prec = 16384; /* Q14 */ move16(); } } @@ -703,8 +704,8 @@ void open_decoder_LPD_fx( { st->hPFstat->reset = 0; move16(); - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */ lerp( st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); lerp( st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); } @@ -714,19 +715,19 @@ void open_decoder_LPD_fx( { IF( st->hPFstat != NULL ) { - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ - Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */ + Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */ } /*feed last value old_synth as it is used for pre-emphasis mem*/ if ( st->hTcxDec != NULL ) { - hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; + hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; /* Q_syn */ move16(); } if ( st->hBPF != NULL ) { - hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* Q_syn */ move16(); } } @@ -735,8 +736,8 @@ void open_decoder_LPD_fx( /* lsf and lsp initialization */ IF( st->ini_frame == 0 ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ set16_fx( st->lsf_cng, 0, M ); } @@ -754,13 +755,13 @@ void open_decoder_LPD_fx( E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); st->plcBackgroundNoiseUpdated = 0; move16(); - Copy( st->lsf_old_fx, st->lsf_q_cng, M ); - Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); - Copy( st->lsp_old_fx, st->lsp_q_cng, M ); - Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); + Copy( st->lsf_old_fx, st->lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsp_old_fx, st->lsp_q_cng, M ); /* Q15 */ + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */ set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768 / 2; + st->last_gain_syn_deemph = 32768 / 2; /* Q15 */ move16(); st->last_gain_syn_deemph_e = 1; move16(); @@ -769,7 +770,7 @@ void open_decoder_LPD_fx( { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768 / 2; + st->last_concealed_gain_syn_deemph = 32768 / 2; /* Q15 */ move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); @@ -796,9 +797,9 @@ void open_decoder_LPD_fx( /*st->noise_filling_index = 0;*/ /* not in BASOP */ - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /* Q2.56 */ st->clas_dec = UNVOICED_CLAS; move16(); @@ -825,12 +826,12 @@ void open_decoder_LPD_fx( { st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ move16(); - st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ + st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ /* Q0 */ move32(); } - st->Mode2_lp_gainc = L_deposit_l( 0 ); + st->Mode2_lp_gainc = L_deposit_l( 0 ); /* 15Q16 */ move32(); - st->Mode2_lp_gainp = L_deposit_l( 0 ); + st->Mode2_lp_gainp = L_deposit_l( 0 ); /* 15Q16 */ move32(); st->prev_widow_left_rect = 0; @@ -853,15 +854,15 @@ void open_decoder_LPD_fx( #else hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; /* Q0 */ move16(); - hTcxDec->conCurrLevelIndex = 0; + hTcxDec->conCurrLevelIndex = 0; /* Q0 */ move16(); hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/ set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); - hTcxDec->conLastFrameLevel_e = 0; + hTcxDec->conLastFrameLevel_e = 0; /* Q15 */ move16(); hTcxDec->conCngLevelBackgroundTrace_e = -6; move16(); @@ -919,24 +920,24 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) + IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) ) { #if 0 PMT("TO be verify, update seems to differ from float") #endif - hTcxLtpDec->tcxltp_pitch_int = st->pit_max; + hTcxLtpDec->tcxltp_pitch_int = st->pit_max; /* Q0 */ move16(); - hTcxLtpDec->tcxltp_pitch_fr = 0; + hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */ move16(); if ( hTcxDec != NULL ) { - hTcxDec->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; /* Q15 */ move16(); } IF( st->ini_frame == 0 ) { - set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); - set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); + set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* hTcxLtpDec->exp_tcxltp_mem_out */ + set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); /* hTcxLtpDec->exp_tcxltp_mem_out */ hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; move16(); hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; @@ -964,10 +965,10 @@ void open_decoder_LPD_fx( move32(); st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); move16(); - st->last_ctx_hm_enabled = 0; + st->last_ctx_hm_enabled = 0; /* Q0 */ move16(); - st->hTcxCfg->resq = getResq( total_brate ); + st->hTcxCfg->resq = getResq( total_brate ); /* Q0 */ move16(); st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/ @@ -983,16 +984,16 @@ void open_decoder_LPD_fx( st->p_bpf_noise_buf = NULL; if ( st->tcxonly == 0 ) { - st->p_bpf_noise_buf = st->bpf_noise_buf; + st->p_bpf_noise_buf = st->bpf_noise_buf; /* q_p_bpf_noise_buf */ } - st->tec_tfa = 0; + st->tec_tfa = 0; /* Q0 */ move16(); test(); test(); test(); IF( EQ_16( bwidth, SWB ) && - ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO ) { st->tec_tfa = 1; move16(); @@ -1017,7 +1018,7 @@ void open_decoder_LPD_fx( move16(); test(); test(); - IF( st->hTcxDec != NULL && GE_32( st->total_brate, 48000 ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->hTcxDec != NULL && GE_32( st->total_brate, 48000 ) && st->element_mode == EVS_MONO ) { st->enablePlcWaveadjust = 1; move16(); @@ -1037,7 +1038,7 @@ void open_decoder_LPD_fx( //#ifdef ADD_IVAS_HTONALMDCTCONC test(); test(); - IF( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( st->element_mode > EVS_MONO && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->tonalMDCTconceal.nScaleFactors = 0; move16(); @@ -1059,16 +1060,16 @@ void open_decoder_LPD_fx( st->second_last_core = -1; move16(); #ifdef NEW_IVAS_OPEN_DEC - IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) + IF( st->hTcxCfg != NULL && st->element_mode != EVS_MONO ) { st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf ); } #endif IF( hTcxDec != NULL ) { - hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; + hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; /*15Q16*/ move16(); - hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; + hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; /*15Q16*/ move16(); } move16(); @@ -1076,14 +1077,14 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO ) { test(); test(); test(); IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || ( EQ_32( st->total_brate, 24400 ) ) ) && - EQ_16( st->element_mode, EVS_MONO ) ) + st->element_mode == EVS_MONO ) { move16(); st->dec_glr = 1; @@ -1110,7 +1111,7 @@ void open_decoder_LPD_fx( #endif if ( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp_gain = 0; + hTcxLtpDec->tcxltp_gain = 0; /* Q15 */ move16(); } return; @@ -1118,32 +1119,33 @@ void open_decoder_LPD_fx( #ifdef IVAS_FLOAT_FIXED void tcxltp_dec_init_fx( - TCX_LTP_DEC_HANDLE hTcxLtpDec, - const Word16 ini_frame, - const Word16 last_codec_mode, - const Word16 element_mode, - const Word16 pit_max, - const Word32 sr_core ) + TCX_LTP_DEC_HANDLE hTcxLtpDec, /* Q0 */ + const Word16 ini_frame, /* Q0 */ + const Word16 last_codec_mode, /* Q0 */ + const Word16 element_mode, /* Q0 */ + const Word16 pit_max, /* Q0 */ + const Word32 sr_core /* Q0 */ +) { - hTcxLtpDec->tcxltp_gain = 0; + hTcxLtpDec->tcxltp_gain = 0; /* Q15 */ move16(); hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); test(); test(); - IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) + IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && element_mode == EVS_MONO ) ) { - hTcxLtpDec->tcxltp_pitch_int = pit_max; + hTcxLtpDec->tcxltp_pitch_int = pit_max; /* Q0 */ move16(); - hTcxLtpDec->tcxltp_pitch_fr = 0; + hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */ move16(); IF( ini_frame == 0 ) { - set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); - set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); - set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); - set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); + set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* exp_tcxltp_mem_in */ + set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); /* exp_tcxltp_mem_out */ + set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); /* exp_tcxltp_mem_in */ + set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); /* exp_tcxltp_mem_out */ hTcxLtpDec->exp_tcxltp_mem_in = 0; move16(); hTcxLtpDec->exp_tcxltp_mem_out = 0; @@ -1186,7 +1188,7 @@ void acelp_plc_mdct_transition_fx( delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); move16(); /*CLDFB delay*/ - Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); + Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* Q_fer_samples */ lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ st->hHQ_core->Q_old_wtda = -1; @@ -1196,21 +1198,21 @@ void acelp_plc_mdct_transition_fx( FOR( i = 0; i < W2; i++ ) { - st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */ move16(); } FOR( ; i < W1; i++ ) { - st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - 1 - ( i - W2 )].v.im, w[W2 - 1 - ( i - W2 )].v.im ), st->hHQ_core->old_out_fx[i + nz] ) ); /* exp_old_out */ move16(); } set16_fx( &st->hHQ_core->old_out_fx[W1 + nz], 0, nz ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX ); - Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); + Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* exp_old_out */ nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS ); - Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); + Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* exp_old_out */ st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; move16(); } @@ -1221,13 +1223,13 @@ void acelp_plc_mdct_transition_fx( #ifdef IVAS_FLOAT_FIXED void open_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 last_total_brate, /* i : last total bitrate */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 last_element_mode, /* i : last element mode */ - const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 last_total_brate, /* i : last total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 last_element_mode, /* i : last element mode Q0*/ + const Word16 is_init, /* i : indicate call from init_decoder() to avoid double TC initialization Q0*/ Word16 *Q_syn_Overl_TDAC, Word16 *Q_fer_samples, Word16 *Q_syn_Overl, @@ -1255,7 +1257,7 @@ void open_decoder_LPD_ivas_fx( if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/ { - st->fscale_old = st->fscale; + st->fscale_old = st->fscale; /* Q0 */ move16(); } @@ -1267,19 +1269,19 @@ void open_decoder_LPD_ivas_fx( move16(); /* initializing variables for frame lengths etc. right in the beginning */ - st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); /* 0.02 in Q15 */ move16(); if ( st->ini_frame == 0 ) { - st->last_L_frame = st->L_frame_past = st->L_frame; + st->last_L_frame = st->L_frame_past = st->L_frame; /* Q0 */ move16(); move16(); } IF( st->hTcxDec != NULL ) { - st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); + st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); /* 0.02 in Q15 */ move16(); - st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */ move16(); if ( ( st->ini_frame == 0 ) ) { @@ -1300,8 +1302,8 @@ void open_decoder_LPD_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || + IF( ( st->element_mode == EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + ( st->element_mode > EVS_MONO && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( ( st->tcxonly != 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; @@ -1333,10 +1335,10 @@ void open_decoder_LPD_ivas_fx( move16(); IF( hTcxDec != NULL ) { - i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); - hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( L_FRAME ) ); /* Q6 */ + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */ move16(); - hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */ move16(); } } @@ -1346,10 +1348,10 @@ void open_decoder_LPD_ivas_fx( move16(); IF( hTcxDec != NULL ) { - i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); - hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); + i = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /* Q6 */ + hTcxDec->pit_max_TCX = extract_l( L_shr( L_mult( st->pit_max, i ), 7 ) ); /* Q0 */ move16(); - hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); + hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); /* Q0 */ move16(); } } @@ -1429,10 +1431,10 @@ void open_decoder_LPD_ivas_fx( move16(); IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); /* Q15 */ hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); /* Q12 */ } IF( st->hIGFDec != NULL ) @@ -1482,16 +1484,16 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { reset_tcx_overl_buf_fx( st->hTcxDec ); - set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); - set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); /* Qx */ + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */ hTcxDec->q_old_synth = 0; move16(); - set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); + set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); /* hTcxDec->q_synth_history_fx */ hTcxDec->q_synth_history_fx = 0; move16(); } - set16_fx( st->syn, 0, M + 1 ); - set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); + set16_fx( st->syn, 0, M + 1 ); /* Q_syn */ + set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */ mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); @@ -1507,9 +1509,9 @@ void open_decoder_LPD_ivas_fx( test(); test(); test(); - IF( st->hTcxDec != NULL && ( NE_16( st->L_frame, st->last_L_frame ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) + IF( st->hTcxDec != NULL && ( NE_16( st->L_frame, st->last_L_frame ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) ) { - set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* q_old_synth */ hTcxDec->q_old_synth = 0; move16(); } @@ -1524,23 +1526,23 @@ void open_decoder_LPD_ivas_fx( test(); IF( ( NE_16( st->L_frame, st->last_L_frame ) ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) || EQ_16( st->last_core, HQ_CORE ) ) { - set16_fx( st->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); /* Qx2.56 */ IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* Qx2.56 */ } } /*Mode 1/2 switching*/ test(); - IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ set16_fx( st->syn, 0, M ); } IF( EQ_16( st->last_core, AMR_WB_CORE ) ) @@ -1606,9 +1608,9 @@ void open_decoder_LPD_ivas_fx( // To be removed later st->tilt_code_fx = TILT_CODE; move16(); - set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); - set16_fx( st->syn, 0, 1 + M ); - set16_fx( st->mem_syn2_fx, 0, M ); + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */ + set16_fx( st->syn, 0, 1 + M ); /* Q_syn */ + set16_fx( st->mem_syn2_fx, 0, M ); /* Q_syn */ /*OLA -> zero */ IF( st->hTcxDec != NULL ) @@ -1618,7 +1620,7 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxCfg != NULL ) { - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* Q_old_out */ *Q_syn_OverlFB = *Q_old_out; move16(); st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ @@ -1630,7 +1632,7 @@ void open_decoder_LPD_ivas_fx( /*OLA for Mode 2 TCX always reset in Mode switching cases*/ IF( st->hHQ_core != NULL ) { - set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); + set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); /* q_old_outLB_fx */ } st->last_core_bfi = TCX_20_CORE; @@ -1667,8 +1669,8 @@ void open_decoder_LPD_ivas_fx( E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M ); } E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ *Q_old_Aq_12_8 = 14; move16(); IF( !st->last_con_tcx ) @@ -1693,14 +1695,14 @@ void open_decoder_LPD_ivas_fx( move16(); IF( !st->last_con_tcx ) { - set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); /* Q_exc */ } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); /* Q12 */ /*Resamp others memories*/ /*Size of LPC syn memory*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Qx */ } /* update of lsf_old only needed in BASOP */ /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1729,7 +1731,7 @@ void open_decoder_LPD_ivas_fx( move16(); IF( st->hBPF != NULL ) { - set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* q_pst_old_syn */ } /* Formant postfilter */ @@ -1748,10 +1750,10 @@ void open_decoder_LPD_ivas_fx( } ELSE { - set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM ); - set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); + set16_fx( st->hPFstat->mem_stp, 0, L_SYN_MEM ); /* Qx */ + set16_fx( st->hPFstat->mem_pf_in, 0, L_SYN_MEM ); /* Qx */ st->hPFstat->reset = 1; - st->hPFstat->gain_prec = 16384; + st->hPFstat->gain_prec = 16384; /* Q14 */ move16(); move16(); } @@ -1799,12 +1801,12 @@ void open_decoder_LPD_ivas_fx( /*feed last value old_synth as it is used for pre-emphasis mem*/ if ( st->hTcxDec != NULL ) { - st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; + st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; /* q_old_synth */ move16(); } if ( st->hBPF != NULL ) { - st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; /* q_pst_old_syn */ move16(); } } @@ -1813,8 +1815,8 @@ void open_decoder_LPD_ivas_fx( /* lsf and lsp initialization */ IF( ( st->ini_frame == 0 ) ) { - Copy( st->lsp_old_fx, st->lspold_uw, M ); - Copy( st->lsf_old_fx, st->lsfold_uw, M ); + Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */ + Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */ set16_fx( st->lsf_cng, 0, M ); } @@ -1822,19 +1824,19 @@ void open_decoder_LPD_ivas_fx( move16(); st->past_gpit = 0; move16(); - st->past_gcode = L_deposit_l( 0 ); + st->past_gcode = L_deposit_l( 0 ); /*15Q16*/ move32(); - st->gc_threshold_fx = L_deposit_l( 0 ); + st->gc_threshold_fx = L_deposit_l( 0 ); /* Q16 */ move32(); E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M ); E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); st->plcBackgroundNoiseUpdated = 0; move16(); - Copy( st->lsf_old_fx, st->lsf_q_cng, M ); - Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); - Copy( st->lsp_old_fx, st->lsp_q_cng, M ); - Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); + Copy( st->lsf_old_fx, st->lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); /* Q2.56 */ + Copy( st->lsp_old_fx, st->lsp_q_cng, M ); /* Q15 */ + Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); /* Q15 */ set16_fx( st->mem_syn_unv_back, 0, M ); st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/ move16(); @@ -1885,12 +1887,12 @@ void open_decoder_LPD_ivas_fx( st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; move16(); move16(); - set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); + set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); /* Q15 */ } - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /* Q2.56 */ + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /* Q2.56 */ st->clas_dec = UNVOICED_CLAS; move16(); @@ -1907,7 +1909,7 @@ void open_decoder_LPD_ivas_fx( test(); IF( st->core == ACELP_CORE && EQ_16( st->last_core, HQ_CORE ) ) { - st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->output_frame_fx = st->hTcxDec->L_frameTCX; /* Q0 */ move16(); frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } @@ -1923,9 +1925,9 @@ void open_decoder_LPD_ivas_fx( move32(); st->Mode2_lp_gainp = L_deposit_l( 0 ); move32(); - st->lp_gainc_fx = 0; + st->lp_gainc_fx = 0; /* Q3 */ move16(); - st->lp_gainp_fx = 0; + st->lp_gainp_fx = 0; /* Q14 */ move16(); IF( st->hTcxDec != NULL ) @@ -1972,7 +1974,7 @@ void open_decoder_LPD_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); + st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); /* 15Q16 */ move32(); } @@ -2028,7 +2030,7 @@ void open_decoder_LPD_ivas_fx( { st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */ move32(); - hBPF->pst_mem_deemp_err_fx = 0; + hBPF->pst_mem_deemp_err_fx = 0; /* Q_syn2 - 1 */ move16(); } ELSE @@ -2103,7 +2105,7 @@ void open_decoder_LPD_ivas_fx( test(); test(); test(); - IF( st->hTonalMDCTConc != NULL && !( GT_16( st->element_mode, EVS_MONO ) && ( st->ini_frame != 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF( st->hTonalMDCTConc != NULL && !( st->element_mode > EVS_MONO && ( st->ini_frame != 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->hTonalMDCTConc->nScaleFactors = 0; move16(); @@ -2135,7 +2137,7 @@ void open_decoder_LPD_ivas_fx( } ELSE { - gettns_temp = L_mult( st->bits_frame_nominal, ( FRAMES_PER_SEC >> 1 ) ); + gettns_temp = L_mult( st->bits_frame_nominal, ( FRAMES_PER_SEC >> 1 ) ); /* Q0 */ } st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( gettns_temp, st->igf, st->element_mode ); move16(); diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index 19b4e08e0..ca9130393 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -12,11 +12,11 @@ #ifdef IVAS_FLOAT_FIXED void reconfig_decoder_LPD_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 bits_frame, /* i : bit budget */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 total_brate, /* i : total bitrate */ - const Word16 L_frame_old /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 bits_frame, /* i : bit budget Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 L_frame_old /* i : frame length Q0*/ ) { UWord16 newLen, oldLen; @@ -93,9 +93,9 @@ void reconfig_decoder_LPD_ivas_fx( { if ( st->rf_flag ) { - i = sub( i, 1 ); + i = i - 1; } - st->hTcxCfg->na_scale = scaleTcxTable[i].scale; + st->hTcxCfg->na_scale = scaleTcxTable[i].scale; /* Q0 */ move16(); BREAK; } @@ -112,7 +112,7 @@ void reconfig_decoder_LPD_ivas_fx( test(); IF( st->hTcxCfg != NULL && ( NE_16( st->fscale, st->fscale_old ) && - !( EQ_16( st->element_mode, EVS_MONO ) && + !( st->element_mode == EVS_MONO && EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->prev_bfi, 0 ) ) ) ) /* no resempling is needed here when recovering from mode 1 @@ -163,12 +163,12 @@ void reconfig_decoder_LPD_ivas_fx( move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } - lerp( &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, oldLen )], &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, newLen )], newLen, oldLen ); + lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen ); } } ELSE { - set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); + set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); /* Qx */ } } } @@ -197,11 +197,11 @@ void reconfig_decoder_LPD_ivas_fx( #ifdef IVAS_FLOAT_FIXED void reconfig_decoder_LPD_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 bits_frame, /* i : bit budget */ - Word16 bwidth, /* i : audio bandwidth */ - Word32 total_brate, /* i : total bitrate */ - Word16 L_frame_old /* i : frame length */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 bits_frame, /* i : bit budget Q0*/ + Word16 bwidth, /* i : audio bandwidth Q0*/ + Word32 total_brate, /* i : total bitrate Q0*/ + Word16 L_frame_old /* i : frame length Q0*/ ) { Word16 newLen; @@ -285,7 +285,7 @@ void reconfig_decoder_LPD_fx( { IF( st->rf_flag ) { - i = sub( i, 1 ); + i = i - 1; move16(); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; @@ -306,7 +306,7 @@ void reconfig_decoder_LPD_fx( test(); IF( st->hTcxCfg != NULL && ( NE_16( st->fscale, st->fscale_old ) && - !( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->last_codec_mode, MODE1 ) && + !( st->element_mode == EVS_MONO && EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, ACELP_CORE ) && st->prev_bfi != 0 ) ) ) /* no resempling is needed here when recovering from mode 1 acelp plc, since the buffers are already sampled with the @@ -357,7 +357,7 @@ void reconfig_decoder_LPD_fx( move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } - lerp( &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, oldLen )], &st->mem_syn_clas_estim_fx[sub( L_SYN_MEM_CLAS_ESTIM, newLen )], newLen, oldLen ); + lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen ); } } ELSE @@ -370,7 +370,7 @@ void reconfig_decoder_LPD_fx( } test(); test(); - + test(); lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR; move16(); IF( GT_16( st->element_mode, IVAS_SCE ) ) diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 0b3ec7709..5e967443d 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -1391,7 +1391,11 @@ ivas_error acelp_core_enc( { if ( ( st->last_Opt_SC_VBR == 1 && st->Opt_SC_VBR == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) { +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif set_f( st->hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); } @@ -1404,8 +1408,6 @@ ivas_error acelp_core_enc( // Word16 voice_factors_fx[NB_SUBFR16k]; floatToFixed_arr( voice_factors, voice_factors_fx, Q15, 5 ); // Saturation Conversion used as last values have garbage values even in float - st->hBWE_TD->bwe_non_lin_prev_scale_fx = floatToFixed( st->hBWE_TD->bwe_non_lin_prev_scale, Q30 ); - Word32 bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; Word16 q_bwe_exc = min( 14, Q_factor_arr( st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ) ); q_bwe_exc = min( q_bwe_exc, Q_factor_arr( bwe_exc, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) - PIT16k_MAX * 2 ) ); @@ -1420,8 +1422,6 @@ ivas_error acelp_core_enc( Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -q_bwe_exc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat_32( st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30 ); fixedToFloat_arrL( bwe_exc_extended_fx, bwe_exc_extended, 2 * q_bwe_exc, L_FRAME32k + NL_BUFF_OFFSET ); fixedToFloat_arr( st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, q_bwe_exc, NL_BUFF_OFFSET ); @@ -1433,7 +1433,11 @@ ivas_error acelp_core_enc( if ( st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA ) { +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif } } @@ -1536,7 +1540,11 @@ ivas_error acelp_core_enc( /* efficient DTX hangover control */ if ( st->hTdCngEnc->burst_ho_cnt > 1 ) { +#ifndef IVAS_FLOAT_FIXED dtx_hangover_control( st, lsp_new ); +#else + dtx_hangover_control_fx( st, lsp_new_fx ); +#endif } } diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index a8959b652..77b055e32 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -309,9 +309,6 @@ void init_coder_ace_plus_ivas_fx( IF( st->hTECEnc != NULL ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - resetTecEnc( st->hTECEnc, st->tec_tfa ); -#endif resetTecEnc_Fx( st->hTECEnc, st->tec_tfa ); } @@ -374,9 +371,6 @@ void init_coder_ace_plus_ivas_fx( IF( st->hPlcExt ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - init_PLC_enc( st->hPlcExt, st->sr_core ); -#endif init_PLC_enc_fx( st->hPlcExt, st->sr_core ); } @@ -561,8 +555,9 @@ void init_coder_ace_plus( if ( st->hTECEnc != NULL ) { +#ifndef IVAS_FLOAT_FIXED resetTecEnc( st->hTECEnc, st->tec_tfa ); -#ifdef IVAS_FLOAT_FIXED +#else resetTecEnc_Fx( st->hTECEnc, st->tec_tfa ); #endif } @@ -627,8 +622,9 @@ void init_coder_ace_plus( if ( st->hPlcExt ) { +#ifndef IVAS_FLOAT_FIXED init_PLC_enc( st->hPlcExt, st->sr_core ); -#ifdef IVAS_FLOAT_FIXED +#else init_PLC_enc_fx( st->hPlcExt, st->sr_core ); #endif } diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index 31ad5d4a0..bb66aa946 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -171,7 +171,11 @@ void core_coder_reconfig( { if ( st->tec_tfa == 0 ) { +#ifndef IVAS_FLOAT_FIXED set_zero( st->hTECEnc->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); +#else + set16_fx( st->hTECEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); +#endif } st->tec_tfa = 1; } diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index fc9c3a017..fe6837e7a 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -86,7 +86,11 @@ void core_switching_pre_enc( if ( st->last_core != ACELP_CORE ) { set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0f; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif } set_f( st->hBWE_FD->old_syn_12k8_16k, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); @@ -234,7 +238,11 @@ void core_switching_pre_enc( set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); /* reset BWE memories */ +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif } if ( st->hBWE_FD != NULL ) @@ -266,7 +274,11 @@ void core_switching_pre_enc( if ( st->hBWE_TD != NULL ) { set_f( st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2 ); +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif } /* reset BWE memories */ @@ -331,7 +343,11 @@ void core_switching_pre_enc( st->hBWE_FD->prev_mode = NORMAL; st->hBWE_FD->modeCount = 0; } +#ifndef IVAS_FLOAT_FIXED st->hBWE_FD->EnergyLF = 0.0f; +#else + st->hBWE_FD->EnergyLF_fx = 0; +#endif st->hBWE_FD->prev_L_swb_norm1 = 8; } @@ -833,8 +849,11 @@ void core_switching_post_enc( #endif } - +#ifndef IVAS_FLOAT_FIXED st->hBWE_TD->bwe_non_lin_prev_scale = 0.0; +#else + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif st->hBWE_FD->mem_deemph_old_syn = 0.0f; } else @@ -856,11 +875,20 @@ void core_switching_post_enc( #else wb_tbe_extras_reset( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb3 ); #endif + +#ifndef IVAS_FLOAT_FIXED if ( st->last_extl != WB_BWE ) { set_f( st->hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( st->hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); } +#else + IF( st->last_extl != WB_BWE ) + { + set16_fx( st->hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( st->hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + } +#endif set_f( st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 ); set_f( st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); @@ -917,9 +945,6 @@ void core_switching_post_enc( st->hBWE_TD->fb_tbe_demph = 0; #ifdef IVAS_FLOAT_FIXED fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); -#endif #else fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); #endif diff --git a/lib_enc/enc_acelp.c b/lib_enc/enc_acelp.c index dec91492b..30ce1c54a 100644 --- a/lib_enc/enc_acelp.c +++ b/lib_enc/enc_acelp.c @@ -1221,6 +1221,7 @@ int16_t E_ACELP_indexing( } +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * E_ACELP_innovative_codebook * @@ -1317,6 +1318,7 @@ void E_ACELP_innovative_codebook( return; } +#endif /*--------------------------------------------------------------------------* diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index ee5bef140..ddb4512cc 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -871,8 +871,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { - floatToFixed_arr16( st->hBWE_TD->decim_state1, st->hBWE_TD->decim_state1_fx, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr16( st->hBWE_TD->decim_state2, st->hBWE_TD->decim_state2_fx, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); floatToFixed_arr16( st->hBWE_TD->old_speech_wb, st->hBWE_TD->old_speech_wb_fx, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); floatToFixed_arr16( st->hBWE_TD->mem_genSHBexc_filt_down_wb2, st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); @@ -886,9 +884,7 @@ ivas_error ivas_core_enc( if ( st->hBWE_FD != NULL ) { - floatToFixed_arr16( st->hBWE_FD->old_input_wb, st->hBWE_FD->old_input_wb_fx, -1, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, -1, L_FRAME48k ); - floatToFixed_arr16( &st->hBWE_FD->mem_old_wtda_swb, &st->hBWE_FD->mem_old_wtda_swb_fx, -1, 1 ); st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further } #endif @@ -920,8 +916,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { - fixedToFloat_arr( st->hBWE_TD->decim_state1_fx, st->hBWE_TD->decim_state1, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); - fixedToFloat_arr( st->hBWE_TD->decim_state2_fx, st->hBWE_TD->decim_state2, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); fixedToFloat_arr( st->hBWE_TD->old_speech_wb_fx, st->hBWE_TD->old_speech_wb, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); fixedToFloat_arr( st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb2, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); @@ -935,9 +929,7 @@ ivas_error ivas_core_enc( if ( st->hBWE_FD != NULL ) { - fixedToFloat_arr( st->hBWE_FD->old_input_wb_fx, st->hBWE_FD->old_input_wb, -1, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, -1, L_FRAME48k ); - st->hBWE_FD->mem_old_wtda_swb = fixedToFloat( st->hBWE_FD->mem_old_wtda_swb_fx, st->Q_old_wtda ); } #endif #endif @@ -1150,22 +1142,12 @@ ivas_error ivas_core_enc( Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; st->hBWE_TD->old_input_fhb_fx_Q = Q_factor_arr( st->hBWE_TD->old_input_fhb, len_old_input_fhb_fx ); floatToFixed_arr( st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); - st->hBWE_TD->prev_fb_energy_fx = floatToFixed( st->hBWE_TD->prev_fb_energy, st->hBWE_TD->prev_fb_energy_fx_Q ); - floatToFixed_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem[0], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[0], 4 ); - floatToFixed_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem[1], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[1], 4 ); - floatToFixed_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem[2], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[2], 4 ); - floatToFixed_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem[3], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[3], 4 ); #endif fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( fb_exc_fx, fb_exc, Q_fb_exc, L_FRAME16k ); fixedToFloat_arr( st->input_fx, st->input, Q_input, L_FRAME48k ); fixedToFloat_arr( st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); - st->hBWE_TD->prev_fb_energy = fixedToFloat( st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->prev_fb_energy_fx_Q ); - fixedToFloat_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], st->hBWE_TD->elliptic_bpf_2_48k_mem[0], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[0], 4 ); - fixedToFloat_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], st->hBWE_TD->elliptic_bpf_2_48k_mem[1], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[1], 4 ); - fixedToFloat_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], st->hBWE_TD->elliptic_bpf_2_48k_mem[2], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[2], 4 ); - fixedToFloat_arrL( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], st->hBWE_TD->elliptic_bpf_2_48k_mem[3], st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q[3], 4 ); #endif #endif } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 12a7d1d8d..598a5094b 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1173,7 +1173,6 @@ ivas_error ivas_compute_core_buffers( { floatToFixed_arr16( st->hBWE_FD->old_wtda_swb, st->hBWE_FD->L_old_wtda_swb_fx, Q_old_inp_16k, L_FRAME48k ); st->Q_old_wtda = -1; // This reset needs to be looked into - floatToFixed_arr16( st->hBWE_FD->old_input_wb, st->hBWE_FD->old_input_wb_fx, -1, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } #endif #endif @@ -1914,7 +1913,6 @@ ivas_error ivas_compute_core_buffers( if ( st->hBWE_FD != NULL ) { fixedToFloat_arr( st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, st->Q_old_wtda, L_FRAME48k ); - fixedToFloat_arr( st->hBWE_FD->old_input_wb_fx, st->hBWE_FD->old_input_wb, -1, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } if ( st->L_frame == L_FRAME16k && element_mode != IVAS_CPE_MDCT ) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index c68d585bb..3206e7ea9 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -581,7 +581,31 @@ ivas_error ivas_dirac_enc( push_next_indice( hMetaData, 1, 1 ); /* encode SID parameters */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IVAS_QDIRECTION *q_direction; + q_direction = &( hQMetaData->q_direction[0] ); + + FOR( b = 0; b < q_direction->cfg.nbands; b++ ) + { + FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) + { + q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); + q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); + } + } +#endif + ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( b = 0; b < q_direction->cfg.nbands; b++ ) + { + q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); + q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); + } +#endif +#else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); +#endif } for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index d6d900b86..cb2965b62 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -918,6 +918,7 @@ ivas_error ivas_enc( else if ( ivas_format == MASA_ISM_FORMAT ) { float *data_separated_object; + Word32 *data_separated_object_fx; int16_t idx_separated_object; int16_t flag_omasa_ener_brate; @@ -943,12 +944,200 @@ ivas_error ivas_enc( idx_separated_object = 0; data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; + data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; + MASA_ENCODER_HANDLE hMasa = st_ivas->hMasa; + int16_t j; + int16_t nchan_transport = st_ivas->nchan_transport; + int16_t nchan_ism = hEncoderConfig->nchan_ism; + Word16 block_m_idx, band_m_idx; + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 32; j++ ) + { + for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + hOMasa->buffer_intensity_real_fx[i][j][k] = floatToFixed( hOMasa->buffer_intensity_real[i][j][k], hOMasa->buffer_intensity_real_q[j] ); + } + } + } + for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) + { + for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j] = floatToFixed( hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j], hOMasa->buffer_energy_q[i] ); + } + } + for ( i = 0; i < nchan_ism; i++ ) + { + hOMasa->chnlToFoaMtx_fx[0][i] = float_to_fix( hOMasa->chnlToFoaMtx[0][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx_fx[1][i] = float_to_fix( hOMasa->chnlToFoaMtx[1][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx_fx[2][i] = float_to_fix( hOMasa->chnlToFoaMtx[2][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx_fx[3][i] = float_to_fix( hOMasa->chnlToFoaMtx[3][i], 31 ); /*q31*/ + } + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx] = floatToFixed( hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx], 31 - hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); + hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = floatToFixed( hOMasa->direction_vector_m[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + } + } + for ( i = 0; i < nchan_ism; i++ ) + { + st_ivas->hIsmMetaData[i]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[i]->azimuth, Q22 ); + st_ivas->hIsmMetaData[i]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[i]->elevation, Q22 ); + } + int16_t norm_data_in = MAX16B; + for ( j = 0; j < nchan_ism + nchan_transport; j++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + data_fx[j][k] = float_to_fix( data_f[j][k], st_ivas->q_data_fx ); + } + norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[j], input_frame ) ); + } + norm_data_in -= 6; /*guard bit is 3->to handle overflow in cldfbAnalysis*/ + for ( j = 0; j < nchan_ism + nchan_transport; j++ ) + { + Scale_sig32( data_fx[j], input_frame, norm_data_in ); + } + st_ivas->q_data_fx = st_ivas->q_data_fx + norm_data_in; + for ( i = 0; i < nchan_ism; i++ ) + { + floatToFixed_arr32( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); + } + for ( i = 0; i < nchan_ism; i++ ) + { + for ( j = 0; j < nchan_transport; j++ ) + { + hOMasa->prev_object_dm_gains_fx[i][j] = float_to_fix16( hOMasa->prev_object_dm_gains[i][j], 15 ); + } + } + for ( i = 0; i < input_frame; i++ ) + { + hOMasa->interpolator_fx[i] = float_to_fix16( hOMasa->interpolator[i], 15 ); + } + // int16_t numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); + for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) + { + hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j], 30 ); + hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].azimuth[i][j], 22 ); + hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[k].elevation[i][j], 22 ); + hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j], 15 ); + } + hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.common_meta.surround_coherence[i][j], 15 ); + hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j], 30 ); + } + } + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); + } + f2me_buf( hOMasa->broadband_energy_sm, hOMasa->broadband_energy_sm_fx, &hOMasa->broadband_energy_sm_e, nchan_ism + nchan_transport ); + f2me_buf( hOMasa->broadband_energy_prev, hOMasa->broadband_energy_prev_fx, &hOMasa->broadband_energy_prev_e, nchan_ism + nchan_transport ); + floatToFixed_arr16( hOMasa->fade_out_gain, hOMasa->fade_out_gain_fx, 15, input_frame ); + floatToFixed_arr16( hOMasa->fade_in_gain, hOMasa->fade_in_gain_fx, 15, input_frame ); +#endif + ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 32; j++ ) + { + for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) + { + hOMasa->buffer_intensity_real[i][j][k] = fixedToFloat( hOMasa->buffer_intensity_real_fx[i][j][k], hOMasa->buffer_intensity_real_q[j] ); + } + } + } + for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) + { + for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j] = me2f( hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j], 31 - hOMasa->buffer_energy_q[i] ); + } + } + for ( i = 0; i < nchan_ism; i++ ) + { + hOMasa->chnlToFoaMtx[0][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[0][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx[1][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[1][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx[2][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[2][i], 31 ); /*q31*/ + hOMasa->chnlToFoaMtx[3][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[3][i], 31 ); /*q31*/ + } + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); + hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ + } + } + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); + for ( int k = 0; k < hMasa->config.numberOfDirections; k++ ) + { + hMasa->masaMetadata.directional_meta[k].energy_ratio[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].energy_ratio_fx[i][j], 30 ); + hMasa->masaMetadata.directional_meta[k].azimuth[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].azimuth_fx[i][j], 22 ); + hMasa->masaMetadata.directional_meta[k].elevation[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].elevation_fx[i][j], 22 ); + hMasa->masaMetadata.directional_meta[k].spread_coherence[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[k].spread_coherence_fx[i][j], 15 ); + } + hMasa->masaMetadata.common_meta.surround_coherence[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j], 15 ); + hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j], 30 ); + } + } + for ( i = 0; i < nchan_ism; i++ ) + { + fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); + } + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + for ( i = 0; i < hOMasa->nbands; i++ ) + { + for ( int k = 0; k < nchan_ism; k++ ) + { + hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = me2f( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], 1 ); + } + } + } + for ( i = 0; i < nchan_ism + nchan_transport; i++ ) + { + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); + } + for ( i = 0; i < nchan_ism; i++ ) + { + st_ivas->hIsmMetaData[i]->azimuth = fixedToFloat( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[i]->elevation = fixedToFloat( st_ivas->hIsmMetaData[i]->elevation_fx, Q22 ); + } + for ( i = 0; i < nchan_ism; i++ ) + { + for ( j = 0; j < nchan_transport; j++ ) + { + hOMasa->prev_object_dm_gains[i][j] = fixedToFloat( hOMasa->prev_object_dm_gains_fx[i][j], 15 ); + } + } + fixedToFloat_arrL( data_separated_object_fx, data_separated_object, st_ivas->q_data_fx, input_frame ); + me2f_buf( hOMasa->broadband_energy_sm_fx, hOMasa->broadband_energy_sm_e, hOMasa->broadband_energy_sm, nchan_ism + nchan_transport ); + me2f_buf( hOMasa->broadband_energy_prev_fx, hOMasa->broadband_energy_prev_e, hOMasa->broadband_energy_prev, nchan_ism + nchan_transport ); +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED } /* Encode ISMs transport channels */ @@ -1195,7 +1384,29 @@ ivas_error ivas_enc( else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) { /* encode Parametric MC parameters and write bitstream */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) + { + for ( int l = 0; l < input_frame; l++ ) + { + data_fx[i][l] = floatToFixed( data_f[i][l], st_ivas->q_data_fx ); + } + } +#endif + ivas_param_mc_enc_fx( st_ivas, hMetaData, data_fx, input_frame ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->hEncoderConfig->nchan_inp; i++ ) + { + for ( int l = 0; l < input_frame; l++ ) + { + data_f[i][l] = fixedToFloat( data_fx[i][l], st_ivas->q_data_fx ); + } + } +#endif +#else ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame ); +#endif if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 412ec99c9..81a43a695 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -60,11 +60,13 @@ static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ); #ifdef IVAS_FLOAT_FIXED static void find_n_largest_fx( const Word32 *input_fx, Word16 exp_input, Word16 *largestIndices, const Word16 numElements, const Word16 numLargest ); + +static void move_metadata_to_qmetadata_fx( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); #else static void find_n_largest( const float *input, int16_t *largestIndices, const int16_t numElements, const int16_t numLargest ); -#endif static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); +#endif static void detect_metadata_composition( const MASA_ENCODER_HANDLE hMasa, uint8_t *joinedSubframes, uint8_t *coherencePresent, uint8_t *isTwoDir ); @@ -81,8 +83,11 @@ static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR #endif static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t nchan_ism, const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); - +#ifndef IVAS_FLOAT_FIXED static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); +#else +static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); +#endif static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const SPHERICAL_GRID_DATA *sphGrid, const uint8_t useSphGrid ); @@ -101,10 +106,13 @@ static void masa_metadata_direction_alignment( MASA_ENCODER_HANDLE hMasa ); * Local constants *-----------------------------------------------------------------------*/ -#define LOWBITRATE_ONSET_ALPHA 0.2f /* Onset values are for processing in frames */ -#define LOWBITRATE_ONSET_BETA 0.92f -#define LOWBITRATE_ONSET_GAIN 1.4f -#define LOWBITRATE_NUM_BANDS 5 +#define LOWBITRATE_ONSET_ALPHA 0.2f /* Onset values are for processing in frames */ +#define LOWBITRATE_ONSET_BETA 0.92f +#define LOWBITRATE_ONSET_GAIN 1.4f +#define LOWBITRATE_ONSET_ALPHA_Q31 429496730 /* Onset values are for processing in frames */ +#define LOWBITRATE_ONSET_BETA_Q31 1975684956 +#define LOWBITRATE_ONSET_GAIN_Q30 1503238554 +#define LOWBITRATE_NUM_BANDS 5 /*-----------------------------------------------------------------------* @@ -178,8 +186,17 @@ ivas_error ivas_masa_enc_open( mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); +#ifdef IVAS_FLOAT_FIXED + hMasa->data.onset_detector_1_fx = 0; + hMasa->data.onset_detector_2_fx = 0; + hMasa->data.q_onset_detector = 0; + move32(); + move32(); + move16(); +#else hMasa->data.onset_detector_1 = 0.0f; hMasa->data.onset_detector_2 = 0.0f; +#endif set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -210,6 +227,14 @@ ivas_error ivas_masa_enc_open( } hOmasaData->lp_noise_CPE = -1; hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero( hOmasaData->energy_ism[i], MASA_FREQUENCY_BANDS ); + set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); + set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); + } +#endif hMasa->data.hOmasaData = hOmasaData; } @@ -291,6 +316,7 @@ ivas_error ivas_masa_encode( int16_t low_bitrate_mode; int32_t masa_total_brate; ivas_error error; + Word16 guard_bits; masa_sid_descriptor = -1; h_orig_metadata = NULL; @@ -371,7 +397,7 @@ ivas_error ivas_masa_encode( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; hMasa->data.q_energy = Q31; - Word16 guard_bits = find_guarded_bits_fx( 9 ); + guard_bits = find_guarded_bits_fx( 9 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); @@ -512,7 +538,7 @@ ivas_error ivas_masa_encode( { hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); + hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); } } @@ -537,7 +563,7 @@ ivas_error ivas_masa_encode( if ( computeCoherence ) { hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); + hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); } hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); @@ -706,12 +732,78 @@ ivas_error ivas_masa_encode( hQMetaData->metadata_max_bits -= lfeBitsWritten; } +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + // Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + hMasa->data.q_energy = Q31; + guard_bits = find_guarded_bits_fx( 9 ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); + } + hMasa->data.q_energy -= guard_bits; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); + } + for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) + { + for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) + { + for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) + { + hQMetaData->q_direction[d].band_data[i].elevation_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].elevation[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].azimuth_fx[j] = float_to_fix( hQMetaData->q_direction[d].band_data[i].azimuth[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j] = floatToFixed( hQMetaData->q_direction[d].band_data[i].energy_ratio[j], Q30 ); + } + } + } +#endif + /* Move data from encoder to qmetadata */ + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) + { + move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); + } +#else /* Move data from encoder to qmetadata */ if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) { move_metadata_to_qmetadata( hMasa, hQMetaData ); } +#endif +#ifdef IVAS_FLOAT_FIXED + + test(); + IF( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + { + reduce_metadata_further_fx( hMasa, hQMetaData, ivas_format ); + + low_bitrate_mode = (Word16) LE_32( ivas_total_brate, 32000 ); + /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ + push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); + hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); + } + for ( int16_t d = 0; d < hQMetaData->no_directions; d++ ) + { + for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) + { + for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) + { + hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); + } + } + } +#endif +#else if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) { reduce_metadata_further( hMasa, hQMetaData, ivas_format ); @@ -722,7 +814,7 @@ ivas_error ivas_masa_encode( push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; } - +#endif /* Encode MASA+ISM metadata */ if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { @@ -940,7 +1032,7 @@ ivas_error ivas_masa_encode( MASA_METADATA_HANDLE hMeta = &( hMasa->masaMetadata ); Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; hMasa->data.q_energy = Q31; - Word16 guard_bits = find_guarded_bits_fx( 9 ); + guard_bits = find_guarded_bits_fx( 9 ); for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); @@ -1078,7 +1170,7 @@ ivas_error ivas_masa_encode( { hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); + hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q15 ); } } @@ -1102,7 +1194,7 @@ ivas_error ivas_masa_encode( if ( computeCoherence ) { hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); + hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q15 ); } hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); @@ -1123,9 +1215,28 @@ ivas_error ivas_masa_encode( } } +#ifdef IVAS_FLOAT_FIXED + move_metadata_to_qmetadata_fx( hMasa, hQMetaData ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( d = 0; d < hQMetaData->no_directions; d++ ) + { + for ( i = hQMetaData->q_direction[d].cfg.start_band; i < hQMetaData->q_direction[d].cfg.nbands; i++ ) + { + for ( j = 0; j < hQMetaData->q_direction[d].cfg.nblocks; j++ ) + { + hQMetaData->q_direction[d].band_data[i].elevation[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].elevation_fx[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].azimuth[j] = fix_to_float( hQMetaData->q_direction[d].band_data[i].azimuth_fx[j], Q22 ); + hQMetaData->q_direction[d].band_data[i].energy_ratio[j] = fixedToFloat( hQMetaData->q_direction[d].band_data[i].energy_ratio_fx[j], Q30 ); + } + } + } +#endif +#else move_metadata_to_qmetadata( hMasa, hQMetaData ); +#endif - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { #ifdef IVAS_FLOAT_FIXED /*=====================================flt-2-fix============================================*/ @@ -1140,8 +1251,30 @@ ivas_error ivas_masa_encode( } free( h_orig_metadata ); - +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IVAS_QDIRECTION *q_direction; + q_direction = &( hQMetaData->q_direction[0] ); + FOR( b = 0; b < q_direction->cfg.nbands; b++ ) + { + FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) + { + q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); + q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); + } + } +#endif + ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( b = 0; b < q_direction->cfg.nbands; b++ ) + { + q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); + q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); + } +#endif +#else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); +#endif /* restore old values */ hMasa->config.numCodingBands = numCodingBands; @@ -2718,18 +2851,18 @@ void ivas_masa_combine_directions_fx( { ambience1dir_fx = L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][i] ); // Q30 ambienceIncrease_fx = L_max( L_sub( ambience1dir_fx, ambience2dir_fx ), 0 ); // Q30 - origSurrCohEne_fx = Mpy_32_16_1( ambience2dir_fx /*Q30*/, hMeta->common_meta.surround_coherence_fx[j][i] /*Q14*/ ); // Q29 + origSurrCohEne_fx = Mpy_32_16_1( ambience2dir_fx /*Q30*/, hMeta->common_meta.surround_coherence_fx[j][i] /*Q15*/ ); // Q30 newSurrCohEne_fx = Mpy_32_16_1( ambienceIncrease_fx /*Q30*/, hMeta->directional_meta[0].spread_coherence_fx[j][i] /*Q15*/ ); // Q30 Word16 exp_y = 0, exp_z = 0; move16(); move16(); - Word32 x = L_add( origSurrCohEne_fx, L_shr( newSurrCohEne_fx, 1 ) ); // Q29 + Word32 x = L_add( origSurrCohEne_fx, newSurrCohEne_fx ); // Q30 Word32 y = BASOP_Util_Add_Mant32Exp( ambience1dir_fx, 1, EPSILON_FX_M, EPSILON_FX_E, &exp_y ); Word16 z = BASOP_Util_Divide3232_Scale( x, y, &exp_z ); - exp_z = add( exp_z, ( sub( sub( 31, Q29 ), exp_y ) ) ); - z = shr( z, sub( 1, exp_z ) ); // Q14 - hMeta->common_meta.surround_coherence_fx[j][i] = s_min( ONE_IN_Q14, z ); + exp_z = add( exp_z, ( sub( 31 - Q30, exp_y ) ) ); + z = shl_sat( z, exp_z ); // Q15 + hMeta->common_meta.surround_coherence_fx[j][i] = s_min( MAX16B, z ); move16(); } } @@ -2961,7 +3094,7 @@ static void find_n_largest( } #endif - +#ifndef IVAS_FLOAT_FIXED static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ) @@ -3032,6 +3165,97 @@ static void move_metadata_to_qmetadata( return; } +#else +static void move_metadata_to_qmetadata_fx( + const MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMeta ) +{ + Word16 dir, sf, band; + UWord8 numCodingBands; + UWord8 numDirections; + UWord8 numSf; + MASA_METADATA_HANDLE hMeta; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + move16(); + move16(); + move16(); + numSf = 4; + if ( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + numSf = 1; + move16(); + } + hMeta = &( hMasa->masaMetadata ); + + FOR( dir = 0; dir < numDirections; dir++ ) + { + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + hQMeta->q_direction[dir].band_data[band].azimuth_fx[sf] = hMeta->directional_meta[dir].azimuth_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].elevation_fx[sf] = hMeta->directional_meta[dir].elevation_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].energy_ratio_fx[sf] = hMeta->directional_meta[dir].energy_ratio_fx[sf][band]; + hQMeta->q_direction[dir].band_data[band].spherical_index[sf] = hMeta->directional_meta[dir].spherical_index[sf][band]; + move32(); + move32(); + move32(); + move16(); + + IF( hQMeta->q_direction[dir].coherence_band_data != NULL ) + { + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = (UWord8) mult_r( hMeta->directional_meta[dir].spread_coherence_fx[sf][band], UINT8_MAX ); + move16(); + } + } + } + } + + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + IF( hQMeta->surcoh_band_data != NULL ) + { + hQMeta->surcoh_band_data[band].surround_coherence[sf] = (UWord8) mult_r( hMeta->common_meta.surround_coherence_fx[sf][band], UINT8_MAX ); + move16(); + } + } + } + + IF( GT_16( numDirections, 1 ) ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + hQMeta->twoDirBands[band] = hMasa->data.twoDirBands[band]; + move16(); + } + hQMeta->numTwoDirBands = hMasa->config.numTwoDirBands; + move16(); + } + + /* Copy spread coherence for DCT-based coding */ + test(); + IF( EQ_16( numSf, 1 ) && hMasa->config.useCoherence ) + { + FOR( dir = 0; dir < numDirections; dir++ ) + { + FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMeta->q_direction[dir].coherence_band_data[band].spread_coherence[0]; + move16(); + } + } + } + } + + return; +} +#endif /* This function studies parametric MASA metadata to provide information for codec configuration */ @@ -3276,7 +3500,7 @@ static void compensate_energy_ratios( } #endif - +#ifndef IVAS_FLOAT_FIXED /* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, @@ -3510,6 +3734,346 @@ static void reduce_metadata_further( return; } +#else +/* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ +static void reduce_metadata_further_fx( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hqmetadata, + const IVAS_FORMAT ivas_format ) +{ + Word16 sf; + Word16 band; + Word16 selectedBand; + Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][LOWBITRATE_NUM_BANDS]; + Word32 totalEnergySum; + UWord8 numCodingBands; + UWord8 computeCoherence; + Word32 onset_filter; + Word16 onset_filter_e, exp; + Word32 bandEnergy; + UWord8 mergeOverFreqBands; + Word32 meanRatio; + Word16 tmp; + + numCodingBands = hMasa->config.numCodingBands; + test(); + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + move16(); + move16(); + + /* Set default values */ + selectedBand = 0; + mergeOverFreqBands = 0; + move16(); + move16(); + + /* Get energy for the input data in 4-subframe, 5-band format */ + totalEnergySum = 0; + move32(); + test(); + IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) ) /* Energy data is in 4-subframe, 24-band format */ + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + Word16 brange[2]; + Word32 eneSum; + Word16 m; + + FOR( band = 0; band < numCodingBands; band++ ) + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); + + eneSum = 0; + move32(); + FOR( m = brange[0]; m < brange[1]; m++ ) + { + eneSum = L_add( eneSum, hMasa->data.energy_fx[sf][m] ); // hMasa->data.q_energy + } + energy[sf][band] = eneSum; // hMasa->data.q_energy + move32(); + totalEnergySum = L_add( totalEnergySum, eneSum ); // hMasa->data.q_energy + } + } + } + ELSE /* Energy data is already in 4-subframe, 5-band format */ + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + energy[sf][band] = hMasa->data.energy_fx[sf][band]; // hMasa->data.q_energy + move32(); + totalEnergySum = L_add( totalEnergySum, energy[sf][band] ); // hMasa->data.q_energy + } + } + } + + /* Determine onsets */ + hMasa->data.onset_detector_1_fx = Mpy_32_32( hMasa->data.onset_detector_1_fx, LOWBITRATE_ONSET_ALPHA_Q31 ); + move32(); + + tmp = hMasa->data.q_onset_detector; + move16(); + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.onset_detector_1_fx, sub( 31, hMasa->data.q_onset_detector ), totalEnergySum, sub( 31, hMasa->data.q_energy ) ) < 0 ) + { + hMasa->data.onset_detector_1_fx = totalEnergySum; // hMasa->data.q_energy + hMasa->data.q_onset_detector = hMasa->data.q_energy; + move32(); + move16(); + } + IF( LT_16( tmp, hMasa->data.q_onset_detector ) ) + { + hMasa->data.onset_detector_1_fx = L_shr( hMasa->data.onset_detector_1_fx, sub( hMasa->data.q_onset_detector, tmp ) ); // tmp + hMasa->data.onset_detector_2_fx = L_add( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // tmp + hMasa->data.q_onset_detector = tmp; + move32(); + move32(); + move16(); + } + ELSE + { + hMasa->data.onset_detector_2_fx = L_add( L_shr( Mpy_32_32( LOWBITRATE_ONSET_BETA_Q31, hMasa->data.onset_detector_2_fx ), sub( tmp, hMasa->data.q_onset_detector ) ), Mpy_32_32( ( ONE_IN_Q31 - LOWBITRATE_ONSET_BETA_Q31 ), hMasa->data.onset_detector_1_fx ) ); // hMasa->data.q_onset_detector + move32(); + } + hMasa->data.onset_detector_2_fx = L_shl( Mpy_32_32( LOWBITRATE_ONSET_GAIN_Q30, L_min( hMasa->data.onset_detector_1_fx, hMasa->data.onset_detector_2_fx ) ), 1 ); // hMasa->data.q_onset_detector + move32(); + + IF( hMasa->data.onset_detector_1_fx != 0 ) + { + onset_filter = L_max( BASOP_Util_Divide3232_Scale_cadence( hMasa->data.onset_detector_2_fx, hMasa->data.onset_detector_1_fx, &onset_filter_e ), 0 ); + + IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, ONE_IN_Q31, 0 ) > 0 ) + { + onset_filter = ONE_IN_Q31; + onset_filter_e = 0; + move32(); + move16(); + } + } + ELSE + { + onset_filter = ONE_IN_Q31; + onset_filter_e = 0; + move32(); + move16(); + } + /* If we have onset, continue checking if we should reduce in frequency instead of time. */ + IF( BASOP_Util_Cmp_Mant32Exp( onset_filter, onset_filter_e, 2126008812 /* 0.99f in Q31 */, 0 ) < 0 ) + { + /* Determine one frequency band to use to represent all frequency bands */ + FOR( band = numCodingBands - 1; band >= 0; band-- ) + { + Word32 threshold; + Word32 bandRatio; + + // threshold = totalEnergySum / ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 0.5f; /* Average energy multiplied with energy ratio of 0.5f */ + threshold = BASOP_Util_Divide3232_Scale_cadence( totalEnergySum, ( MAX_PARAM_SPATIAL_SUBFRAMES * LOWBITRATE_NUM_BANDS ) * 2, &exp ); /* Average energy multiplied with energy ratio of 0.5f */ + exp = add( exp, sub( sub( 31, hMasa->data.q_energy ), 31 ) ); + bandRatio = hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[0]; // Q30 + move32(); + + bandEnergy = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + bandEnergy = L_add( bandEnergy, energy[sf][band] ); + } + + IF( BASOP_Util_Cmp_Mant32Exp( Mpy_32_32( L_shr( bandEnergy, 2 ), bandRatio ), sub( 31 + 1, hMasa->data.q_energy ), threshold, exp ) > 0 ) + { + selectedBand = band; + move16(); + BREAK; + } + } + + /* Determine if to merge over frequency instead of time */ + meanRatio = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + meanRatio = L_add( meanRatio, Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ) ); // hMasa->data.q_energy - 1 + } + } + IF( totalEnergySum != 0 ) + { + meanRatio = BASOP_Util_Divide3232_Scale_cadence( meanRatio, totalEnergySum, &exp ); + exp = add( exp, 1 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy => 1 + } + ELSE + { + meanRatio = MAX_32; + exp = 31; + move32(); + move16(); + } + + /* If the ratio of the selected band is larger than the average ratio of all bands and if there is an onset, merge over frequency bands. + * Otherwise, merge over subframes. */ + IF( BASOP_Util_Cmp_Mant32Exp( hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[0], 1, meanRatio, exp ) > 0 ) + { + mergeOverFreqBands = 1; + move16(); + } + ELSE + { + mergeOverFreqBands = 0; + move16(); + } + } + ELSE + { + mergeOverFreqBands = 0; + move16(); + } + + /* Merge values over subframes or frequency bands, depending on which one is less important */ + IF( !mergeOverFreqBands ) /* Merge values over subframes */ + { + Word32 xSum, ySum, zSum; + Word64 W_xSum_sq, W_ySum_sq, W_tmp; + Word32 bandSumEnergy; + Word16 aziRad, eleRad, q_shift, exp_diff; + Word32 x, y, z; + Word32 veclen, L_tmp; + + FOR( band = 0; band < numCodingBands; band++ ) + { + xSum = 0; + ySum = 0; + zSum = 0; + bandSumEnergy = 0; + move32(); + move32(); + move32(); + move32(); + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + aziRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].azimuth_fx[sf], PI_OVER_180_Q22 ) ); + eleRad = extract_l( Mpy_32_32( hqmetadata->q_direction[0].band_data[band].elevation_fx[sf], PI_OVER_180_Q22 ) ); + veclen = Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ); // hMasa->data.q_energy - 1 + + x = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); + y = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); + z = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), veclen ); // (Q29, hMasa->data.q_energy - Q1) -> hMasa->data.q_energy - Q3 + move32(); + + xSum = L_add( xSum, x ); + ySum = L_add( ySum, y ); + zSum = L_add( zSum, z ); + + bandSumEnergy = L_add( bandSumEnergy, energy[sf][band] ); + } + + aziRad = BASOP_util_atan2( ySum, xSum, 0 ); // Q13 + W_xSum_sq = W_mult0_32_32( xSum, xSum ); // 2 * hMasa->data.q_energy - Q6 + W_ySum_sq = W_mult0_32_32( ySum, ySum ); // 2 * hMasa->data.q_energy - Q6 + W_tmp = W_add( W_xSum_sq, W_ySum_sq ); // 2 * hMasa->data.q_energy - Q6 + q_shift = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, q_shift ) ); // 2 * hMasa->data.q_energy - Q6 + (q_shift -32) + exp_diff = sub( Q31, add( sub( imult1616( 2, hMasa->data.q_energy ), Q6 ), sub( q_shift, 32 ) ) ); + L_tmp = Sqrt32( L_tmp, &exp_diff ); + eleRad = BASOP_util_atan2( zSum, L_tmp, sub( sub( 34, hMasa->data.q_energy ), exp_diff ) ); // Q13 + + hqmetadata->q_direction[0].band_data[band].azimuth_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, aziRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + hqmetadata->q_direction[0].band_data[band].elevation_fx[0] = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, eleRad ), Q1 ); // ((Q25, Q13) -> Q23) >> Q1 -> Q22 + + /* Energy ratio is already merged through time */ + test(); + IF( computeCoherence && hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + Word16 spreadCoh; + Word32 spreadCohSum = 0; + move32(); + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + spreadCoh = div_s( (Word16) hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf], 255 ); // Q15 + spreadCohSum = L_add( spreadCohSum, Mpy_32_16_1( energy[sf][band], spreadCoh ) ); + } + // hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (uint8_t) roundf( spreadCohSum / ( bandSumEnergy + EPSILON ) * 255.0f ); + tmp = BASOP_Util_Divide3232_Scale( spreadCohSum, bandSumEnergy, &exp ); + tmp = mult_r( tmp, 32640 /* 255 in Q7 */ ); // 15 - exp + 7 - 15 => 7 - exp + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0] = (UWord8) shr( tmp, sub( 7, exp ) ); // Q0 + move16(); + + /* Copy spread coherence to the rest of subframes for the coherence coding algorithm. */ + FOR( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[0]; + move16(); + } + } + + /* Surround coherence is already merged through time */ + } + } + + hqmetadata->q_direction->cfg.nblocks = 1; + hMasa->config.joinedSubframes = 1; + move16(); + move16(); + } + ELSE /* Merge values over frequency bands */ + { + /* Use the selected frequency band to represent all data */ + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->q_direction[0].band_data[0].azimuth_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].azimuth_fx[sf]; + hqmetadata->q_direction[0].band_data[0].elevation_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].elevation_fx[sf]; + hqmetadata->q_direction[0].band_data[0].energy_ratio_fx[sf] = hqmetadata->q_direction[0].band_data[selectedBand].energy_ratio_fx[sf]; + move32(); + move32(); + move32(); + if ( hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[selectedBand].spread_coherence[sf]; + move16(); + } + if ( hqmetadata->surcoh_band_data != NULL ) + { + hqmetadata->surcoh_band_data[0].surround_coherence[sf] = hqmetadata->surcoh_band_data[selectedBand].surround_coherence[sf]; + move16(); + } + } + + /* Copy coherence to rest of bands for the coherence coding algorithm. */ + FOR( band = 1; band < numCodingBands; band++ ) + { + IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hqmetadata->q_direction[0].coherence_band_data[0].spread_coherence[sf]; + move16(); + } + } + IF( hqmetadata->q_direction[0].coherence_band_data != NULL ) + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + hqmetadata->surcoh_band_data[band].surround_coherence[sf] = hqmetadata->surcoh_band_data[0].surround_coherence[sf]; + move16(); + } + } + } + + hqmetadata->q_direction[0].cfg.nbands = 1; + move16(); + } + + return; +} +#endif #ifdef IVAS_FLOAT_FIXED @@ -3526,8 +4090,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( Word16 maxLFESubFrameEner_e; Word32 log2LFEaverage; Word32 log2LFEratio[4]; - Word16 log2LFEratio_16[4]; - Word16 xqv[4]; + Word32 xqv[4]; Word32 linearLFEaverage; Word16 linearLFEaverage_e; Word16 lfeToTotalEnergyRatioIndices[3]; @@ -3535,10 +4098,6 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( Word16 lfeBitsWritten; Word32 maxVal; Word16 maxVal_e; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif VQLevels = 0; move16(); @@ -3619,20 +4178,12 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( move16(); IF( EQ_16( hMasa->data.prevq_lfeIndex, 1 ) ) { -#ifdef BASOP_NOGLOB - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add_o( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, 251255587 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q31 */, &Overflow ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q31 -#else hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, 251255587 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q31 */ ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q31 -#endif move32(); } ELSE { -#ifdef BASOP_NOGLOB - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add_o( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31, &Overflow ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 -#else - hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 -#endif + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 move32(); } } @@ -3704,8 +4255,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( IF( VQLevels > 0 ) { - Copy_Scale_sig32_16( log2LFEratio, log2LFEratio_16, 4, Q16 + Q13 - Q25 ); // Q13 - lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio_16, 0, xqv, McMASA_LFEGain_vectors_fx_q13, 4, VQLevels ); + lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio, 0, xqv, McMASA_LFEGain_vectors_fx_q25, 4, VQLevels ); move16(); } } @@ -6151,6 +6701,28 @@ static void ivas_encode_masaism_metadata( * * Merge MASA transport channels *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_merge_masa_transports_fx( + Word32 data_in_f1_fx[][L_FRAME48k], + Word32 *data_in_f2_fx[], + Word32 *data_out_f_fx[], + const Word16 input_frame, + const Word16 num_transport_channels ) +{ + Word16 i, j; + + FOR( i = 0; i < num_transport_channels; i++ ) + { + FOR( j = 0; j < input_frame; j++ ) + { + data_out_f_fx[i][j] = L_add( data_in_f1_fx[i][j], data_in_f2_fx[i][j] ); + move32(); + } + } + + return; +} +#endif // IVAS_FLOAT_FIXED void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 1404d215d..119ae117b 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -441,31 +441,20 @@ void ivas_param_mc_enc_close( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - float *data_f[], /* i/o: input/transport MC data */ - const int16_t input_frame /* i : input frame length */ +void ivas_param_mc_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + Word32 *data_f_fx[], /* i/o: input/transport MC data Q11 */ + const Word16 input_frame /* i : input frame length */ ) { - int16_t i, j, k; -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[12]; - for ( k = 0; k < 12; k++ ) - { - data_f_fx[k] = (Word32 *) malloc( input_frame * sizeof( Word32 ) ); - } -#endif - float Cy_sum[PARAM_MC_MAX_PARAMETER_BANDS][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; - float Cx_sum[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS]; - float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; - int16_t ILD_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ILD_MAP]; - int16_t ICC_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ICC_MAP]; - uint16_t bit_buffer[PARAM_MC_MAX_BITS]; - int16_t bit_pos; - int16_t band_step; - float data_dmx[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED + Word16 i, k; + Word16 ILD_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ILD_MAP]; + Word16 ICC_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ICC_MAP]; + UWord16 bit_buffer[PARAM_MC_MAX_BITS]; + Word16 bit_pos; + Word16 band_step; + Word16 data_f_fx16[L_FRAME48k]; Word32 data_dmx_fx[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; Word16 data_dmx_fx16[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; Word32 Cy_sum_fx[PARAM_MC_MAX_PARAMETER_BANDS][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; @@ -473,32 +462,53 @@ void ivas_param_mc_enc( Word32 Cx_sum_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 Cx_sum_e[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 ILD_q_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; -#endif - int16_t ch; - int16_t band; + Word16 ch; + Word16 band; PARAM_MC_ENC_HANDLE hParamMC; - int16_t nchan_inp; + Word16 nchan_inp; push_wmops( "param_mc_enc" ); - /* initializations */ - hParamMC = st_ivas->hParamMC; - bit_pos = 0; - band_step = 1; - nchan_inp = st_ivas->hEncoderConfig->nchan_inp; - - for ( band = 0; band < PARAM_MC_MAX_PARAMETER_BANDS; band++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - for ( ch = 0; ch < MAX_CICP_CHANNELS; ch++ ) + Word16 cpe_idx = ch / 2; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) { - set_zero( Cy_sum[band][ch], MAX_CICP_CHANNELS ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); } - for ( ch = 0; ch < PARAM_MC_MAX_TRANSPORT_CHANS; ch++ ) + + for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) { - set_zero( Cx_sum[band][ch], PARAM_MC_MAX_TRANSPORT_CHANS ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); } + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e = 31 - 7; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e = 31 - 7; + + for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); + } + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, Q15 - ATTACKTHRESHOLD_E ); + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); } -#ifdef IVAS_FLOAT_FIXED +#endif + + /* initializations */ + hParamMC = st_ivas->hParamMC; + bit_pos = 0; + move16(); + band_step = 1; + move16(); + nchan_inp = st_ivas->hEncoderConfig->nchan_inp; + move16(); + FOR( band = 0; band < PARAM_MC_MAX_PARAMETER_BANDS; band++ ) { FOR( ch = 0; ch < MAX_CICP_CHANNELS; ch++ ) @@ -512,196 +522,89 @@ void ivas_param_mc_enc( set16_fx( Cx_sum_e[band][ch], 0, PARAM_MC_MAX_TRANSPORT_CHANS ); } } -#endif - for ( band = 0; band < PARAM_MC_MAX_PARAMETER_BANDS; band++ ) - { - set_zero( ILD_q[band], PARAM_MC_SZ_ILD_MAP ); - } - set_s( ILD_idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ILD_MAP ); - set_s( ICC_idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ICC_MAP ); + set16_fx( ILD_idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ILD_MAP ); + set16_fx( ICC_idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_SZ_ICC_MAP ); /* update parameter frame index */ - hParamMC->hMetadataPMC.param_frame_idx = ( hParamMC->hMetadataPMC.param_frame_idx + 1 ) % PARAM_MC_PARAMETER_FRAMES; + hParamMC->hMetadataPMC.param_frame_idx = add( hParamMC->hMetadataPMC.param_frame_idx, 1 ) % PARAM_MC_PARAMETER_FRAMES; + move16(); /* DMX generation*/ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_inp; i++ ) - { - floatToFixed_arrL( data_f[i], data_f_fx[i], 11, input_frame ); - } -#endif ivas_param_mc_dmx_fx( hParamMC, data_f_fx, data_dmx_fx, input_frame, nchan_inp, st_ivas->nchan_transport ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < 3; i++ ) - { - fixedToFloat_arrL( data_dmx_fx[i], data_dmx[i], 11, input_frame ); - } -#endif -#else - ivas_param_mc_dmx( hParamMC, data_f, data_dmx, input_frame, nchan_inp, st_ivas->nchan_transport ); -#endif /* Transient Detector */ - switch ( st_ivas->nchan_transport ) + SWITCH( st_ivas->nchan_transport ) { - case 2: case 3: + case 2: case 4: { - int16_t bAttackPresent[PARAM_MC_MAX_TRANSPORT_CHANS]; - int16_t attackIdx[PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 bAttackPresent[PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 attackIdx[PARAM_MC_MAX_TRANSPORT_CHANS]; set16_fx( attackIdx, -1, PARAM_MC_MAX_TRANSPORT_CHANS ); set16_fx( bAttackPresent, 0, PARAM_MC_MAX_TRANSPORT_CHANS ); - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - Word16 cpe_idx = ch / 2; - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); - } - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - - floatToFixed_arr16( data_dmx[ch], data_dmx_fx16[ch], -1, input_frame ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - -#endif + Word16 cpe_idx = shr( ch, 1 ); + Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], -Q1 - Q11, input_frame ); // Q11 -> Q(-1) RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); - - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); - } -#endif -#else - RunTransientDetection( data_dmx[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg, &st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e, NSUBBLOCKS + MAX_TD_DELAY ); - f2me_buf( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg, &st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_e, NSUBBLOCKS + MAX_TD_DELAY + 1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, Q15 - ATTACKTHRESHOLD_E ); -#endif ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); -#else - ivas_param_mc_transient_detection( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); -#endif } /* if more than one attack, use the earlier */ hParamMC->hMetadataPMC.bAttackPresent = 0; + move16(); hParamMC->hMetadataPMC.attackIndex = 16; + move16(); - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - hParamMC->hMetadataPMC.bAttackPresent = max( hParamMC->hMetadataPMC.bAttackPresent, bAttackPresent[ch] ); + hParamMC->hMetadataPMC.bAttackPresent = s_max( hParamMC->hMetadataPMC.bAttackPresent, bAttackPresent[ch] ); + move16(); } - if ( hParamMC->hMetadataPMC.bAttackPresent ) + IF( hParamMC->hMetadataPMC.bAttackPresent ) { - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - hParamMC->hMetadataPMC.attackIndex = min( hParamMC->hMetadataPMC.attackIndex, attackIdx[ch] ); + hParamMC->hMetadataPMC.attackIndex = s_min( hParamMC->hMetadataPMC.attackIndex, attackIdx[ch] ); + move16(); } } - else + ELSE { hParamMC->hMetadataPMC.attackIndex = 0; + move16(); } } - break; + BREAK; } - /* Encoding */ - /* parameter estimation*/ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++ ) - { - floatToFixed_arrL( hParamMC->prev_ilds[i], hParamMC->prev_ilds_fx[i], Q21, PARAM_MC_SZ_ILD_MAP ); - } -#endif + /* Encoding */ + /* parameter estimation*/ ivas_param_mc_param_est_enc_fx( hParamMC, data_f_fx, Cy_sum_fx, Cy_sum_e, Cx_sum_fx, Cx_sum_e, input_frame, nchan_inp, st_ivas->nchan_transport ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++ ) + + IF( hParamMC->hMetadataPMC.bAttackPresent ) { - for ( j = 0; j < MAX_CICP_CHANNELS; j++ ) - { - for ( k = 0; k < MAX_CICP_CHANNELS; k++ ) - { - Cy_sum[i][j][k] = me2f( Cy_sum_fx[i][j][k], Cy_sum_e[i][j][k] ); - } - } - for ( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) - { - for ( k = 0; k < PARAM_MC_MAX_TRANSPORT_CHANS; k++ ) - { - Cx_sum[i][j][k] = me2f( Cx_sum_fx[i][j][k], Cx_sum_e[i][j][k] ); - } - } + band_step = PARAM_MC_TRANSIENT_BAND_STEP; + move16(); } - for ( i = 0; i < hParamMC->hFbMixer->fb_cfg->num_in_chans; i++ ) + ELSE { - fixedToFloat_arrL( hParamMC->hFbMixer->ppFilterbank_prior_input_fx[i], hParamMC->hFbMixer->ppFilterbank_prior_input[i], Q11, input_frame / PARAM_MC_MDFT_NO_SLOTS ); + band_step = 1; + move16(); } -#endif -#else - ivas_param_mc_param_est_enc( hParamMC, data_f, Cy_sum, Cx_sum, input_frame, nchan_inp, st_ivas->nchan_transport ); -#endif - - band_step = hParamMC->hMetadataPMC.bAttackPresent ? PARAM_MC_TRANSIENT_BAND_STEP : 1; /* ILD parameter quantization */ - for ( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) + FOR( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) { -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_quantize_ilds_fx( hParamMC, Cy_sum_fx[k], Cy_sum_e[k], Cx_sum_fx[k], Cx_sum_e[k], k, nchan_inp, st_ivas->nchan_transport, ILD_idx, ILD_q_fx[k] ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( hParamMC->prev_ilds_fx[i], hParamMC->prev_ilds[i], Q21, PARAM_MC_SZ_ILD_MAP ); -#endif -#else - ivas_param_mc_quantize_ilds( hParamMC, Cy_sum[k], Cx_sum[k], k, nchan_inp, st_ivas->nchan_transport, ILD_idx, ILD_q[k] ); -#endif } #ifndef FIX_901_PARAMMC_DEAD_CODE @@ -717,92 +620,30 @@ void ivas_param_mc_enc( #endif /* ICC parameter quantization */ - for ( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) + FOR( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) { -#ifdef IVAS_FLOAT_FIXED ivas_param_mc_quantize_iccs_fx( hParamMC, Cy_sum_fx[k], Cy_sum_e[k], k, nchan_inp, ICC_idx ); -#else - ivas_param_mc_quantize_iccs( hParamMC, Cy_sum[k], k, nchan_inp, ICC_idx ); -#endif } /* time domain DMX generation*/ /* just copy data_dmx generated above, contains already the downmix */ - for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) + FOR( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - mvr2r( data_dmx[ch], data_f[ch], input_frame ); + Copy32( data_dmx_fx[ch], data_f_fx[ch], input_frame ); } /* we have to run the transient detector on the second channel of the last CPE if we have an odd number of transport channels */ - if ( st_ivas->nchan_transport > 2 ) + IF( GT_16( st_ivas->nchan_transport, 2 ) ) { - for ( ; ch < st_ivas->nCPE * CPE_CHANNELS; ch++ ) + FOR( ; ch < st_ivas->nCPE * CPE_CHANNELS; ch++ ) { - int16_t cpe_idx = ch / 2; - - set_zero( data_f[ch], input_frame ); - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 data_fx[L_FRAME48k]; - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); - } - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); - } - - - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], -1 ); - } - - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); - - floatToFixed_arr16( data_f[ch], data_fx, -1, input_frame ); - - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); - -#endif - - RunTransientDetection_ivas_fx( data_fx, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); - - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); - } + Word16 cpe_idx = shr( ch, 1 ); - FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); - } + set32_fx( data_f_fx[ch], 0, input_frame ); + set16_fx( data_f_fx16, 0, input_frame ); - FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) - { - st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); - } - -#endif -#else - RunTransientDetection( data_f[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); -#endif + RunTransientDetection_ivas_fx( data_f_fx16, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); } } @@ -814,12 +655,37 @@ void ivas_param_mc_enc( /* updates */ hParamMC->hMetadataPMC.last_coded_bwidth = hParamMC->hMetadataPMC.coded_bwidth; + move16(); -#ifdef IVAS_FLOAT_FIXED - for ( k = 0; k < 12; k++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { - free( data_f_fx[k] ); + Word16 cpe_idx = ch / 2; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); + + for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + for ( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + for ( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + } + } + + for ( i = 0; i < hParamMC->hFbMixer->fb_cfg->num_in_chans; i++ ) + { + fixedToFloat_arrL( hParamMC->hFbMixer->ppFilterbank_prior_input_fx[i], hParamMC->hFbMixer->ppFilterbank_prior_input[i], Q11, input_frame / PARAM_MC_MDFT_NO_SLOTS ); } + #endif pop_wmops(); diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index b56db211b..ddb275e08 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -1462,6 +1462,15 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( move16(); move16(); move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { @@ -1470,8 +1479,8 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( move16(); move16(); - Scale_sig32( pcm_in_fx[2 * i], input_frame, Q14 - Q_data_f ); - Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, Q14 - Q_data_f ); + Scale_sig32( pcm_in_fx[2 * i], input_frame, sub( Q14, Q_data_f ) ); + Scale_sig32( pcm_in_fx[2 * i + 1], input_frame, sub( Q14, Q_data_f ) ); } /*-----------------------------------------------------------------------------------------* @@ -1482,8 +1491,10 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( { ivas_transient_det_process_fx( hMCParamUpmix->hTranDet[2 * i], pcm_in_fx[2 * i], input_frame, transient_det_l ); ivas_transient_det_process_fx( hMCParamUpmix->hTranDet[2 * i + 1], pcm_in_fx[2 * i + 1], input_frame, transient_det_r ); + test(); transient_det[i][0] = transient_det_l[0] || transient_det_r[0]; move16(); + test(); transient_det[i][1] = transient_det_l[0] || transient_det_r[0]; move16(); /* should probably be transient_det_l[1] || transient_det_r[1] , but choosing 0 reproduces the before merge state */ @@ -1506,7 +1517,8 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( move32(); } - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; + // l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); Word16 gb = find_guarded_bits_fx( l_ts ); @@ -1576,7 +1588,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( set_s( q_cov_dtx_real[i], Q31, MC_PARAMUPMIX_NCH ); } - set_s( q_ppIn_FR, Q14 - gb, MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); + set_s( q_ppIn_FR, sub( Q14, gb ), MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH ); ivas_enc_cov_handler_process_fx( hMCParamUpmix->hCovEnc[b], pp_in_fr_real_fx, pp_in_fr_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hMCParamUpmix->hFbMixer->pFb, 0, hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands, MC_PARAMUPMIX_NCH, 0 /*dtx_vad*/, transient_det[b], HOA_md_ind, NULL, NULL, NULL, 0, 0 ); FOR( i = 0; i < MC_PARAMUPMIX_NCH; i++ ) @@ -1589,10 +1601,14 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( } maxbands = hMCParamUpmix->hFbMixer->pFb->filterbank_num_bands; - Word16 exp_alpha_buff[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] = { { 0 }, { 0 } }; - Word16 exp_beta_buff[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS] = { { 0 }, { 0 } }; - move16(); move16(); + Word16 exp_alpha_buff[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; + Word16 exp_beta_buff[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + { + set16_fx( &exp_alpha_buff[i][0], 0, IVAS_MAX_NUM_BANDS ); + set16_fx( &exp_beta_buff[i][0], 0, IVAS_MAX_NUM_BANDS ); + } FOR( b = 0; b < MC_PARAMUPMIX_COMBINATIONS; b++ ) { @@ -1603,7 +1619,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( Word16 exp_tmp = 0; move16(); - Word32 tmp = BASOP_Util_Add_Mant32Exp( ryy_fx, 31 - ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][1][bnd] ), EPSILON_FX_M, EPSILON_FX_E, &exp_tmp ); + Word32 tmp = BASOP_Util_Add_Mant32Exp( ryy_fx, sub( 31, ( hMCParamUpmix->hCovEnc[b]->pCov_state->q_cov_real_per_band[1][1][bnd] ) ), EPSILON_FX_M, EPSILON_FX_E, &exp_tmp ); exp_cmat = 0; move16(); cmat_fx = BASOP_Util_Divide3232_Scale( rxy_fx, tmp, &exp_cmat ); @@ -1612,7 +1628,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( Word16 alpha_fx = 0, exp_alpha_var = 0; move16(); move16(); - exp_alpha_var = BASOP_Util_Add_MantExp( cmat_fx, exp_cmat + 1, negate( ONE_IN_Q14 ), 1, &alpha_fx ); + exp_alpha_var = BASOP_Util_Add_MantExp( cmat_fx, add( exp_cmat, 1 ), negate( ONE_IN_Q14 ), 1, &alpha_fx ); rxx_fx = hMCParamUpmix->cov_real_fx[b][0][0][bnd]; Word32 tmp_2 = L_mult( cmat_fx, cmat_fx ); // exp_cmat * 2 @@ -1678,9 +1694,9 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( { FOR( j = 0; j < maxbands; j++ ) { - alphas_fx[i][j] = L_shr( alphas_fx[i][j], max_exp_alpha_buff - exp_alpha_buff[i][j] ); + alphas_fx[i][j] = L_shr( alphas_fx[i][j], sub( max_exp_alpha_buff, exp_alpha_buff[i][j] ) ); move16(); - betas_fx[i][j] = L_shr( betas_fx[i][j], max_exp_beta_buff - exp_beta_buff[i][j] ); + betas_fx[i][j] = L_shr( betas_fx[i][j], sub( max_exp_beta_buff, exp_beta_buff[i][j] ) ); move16(); } } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index fbd04aa2a..77f3d3184 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -155,6 +155,12 @@ ivas_error ivas_omasa_enc_open( return error; } } +#ifdef IVAS_FLOAT_FIXED + set_zero_fx( &hOMasa->chnlToFoaMtx_fx[0][0], DIRAC_MAX_ANA_CHANS * MCMASA_MAX_ANA_CHANS ); +#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED + set_zero( &hOMasa->chnlToFoaMtx[0][0], DIRAC_MAX_ANA_CHANS * MCMASA_MAX_ANA_CHANS ); +#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED +#endif /* intensity 3-dim */ for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -578,63 +584,90 @@ void ivas_omasa_set_config( * Main OMASA encoding function *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - float *data_in_f[], /* i/o: Input / transport audio signals */ - Word32 *data_in[], /* i/o: Input / transport audio signals */ - Word16 q_data, /* i:Q0 Stores the q for data_in_f */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_transport, /* i : Number of transport channels */ - const int16_t nchan_ism, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - float *data_separated_object, /* o : Separated object audio signal */ - int16_t *idx_separated_object /* o : Index of the separated object */ +void ivas_omasa_enc_fx( + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + Word32 *data_in[], /* i/o: Input / transport audio signals */ + Word16 q_data, /* i:Q0 Stores the q for data_in_f */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_transport, /* i : Number of transport channels */ + const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + Word32 *data_separated_object_fx, /* o : Separated object audio signal */ + Word16 *idx_separated_object /* o : Index of the separated object */ ) { - int16_t i, j; - float data_out_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED + Word16 i, j; Word32 data_out[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; -#endif // IVAS_FLOAT_FIXED /* Determine separated object (when applicable) */ - if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - float broadband_energy[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - int16_t loudest_object; - int16_t selected_object; - int16_t nchan_all_inp; - float alpha; - uint8_t fade_out_separate_object; - uint8_t fade_in_separate_object; - + Word32 broadband_energy_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + Word16 broadband_energy_e[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + Word16 max_broadband_energy_e = MIN_16; + move16(); + Word16 loudest_object; + Word16 selected_object; + Word16 nchan_all_inp; + UWord8 fade_out_separate_object; + UWord8 fade_in_separate_object; + Word32 temp32; /*temp32_e*/ /* Estimate broadband energies */ - nchan_all_inp = nchan_ism + nchan_transport; - set_zero( broadband_energy, nchan_all_inp ); - for ( i = 0; i < nchan_all_inp; i++ ) + nchan_all_inp = add( nchan_ism, nchan_transport ); + set_zero_fx( broadband_energy_fx, nchan_all_inp ); + set16_fx( broadband_energy_e, 0, nchan_all_inp ); + + FOR( i = 0; i < nchan_all_inp; i++ ) { - for ( j = 0; j < input_frame; j++ ) + FOR( j = 0; j < input_frame; j++ ) { - broadband_energy[i] += data_in_f[i][j] * data_in_f[i][j]; + temp32 = L_shl( data_in[i][j], 6 ); /* scaling data_in to prevent zeroes values in Mpy_32_32 due to precision loss*/ + broadband_energy_fx[i] = BASOP_Util_Add_Mant32Exp( broadband_energy_fx[i], broadband_energy_e[i], Mpy_32_32( temp32, temp32 ), sub( 50, shl( q_data, 1 ) ) /*exponent=62-2*(q+6)*/, &broadband_energy_e[i] ); + move32(); } + max_broadband_energy_e = s_max( max_broadband_energy_e, broadband_energy_e[i] ); /*calculating maximum exponent for all values in broadband_energy_e*/ + } + + /*scaling all the values in broadband_energy_fx to max_broadband_energy_e*/ + FOR( i = 0; i < nchan_all_inp; i++ ) + { + broadband_energy_fx[i] = L_shr( broadband_energy_fx[i], sub( max_broadband_energy_e, broadband_energy_e[i] ) ); + move32(); + } + /*making exponent for hOMasa->broadband_energy_sm_fx and broadband_energy_fx equal as they are used in addition later*/ + IF( GT_16( max_broadband_energy_e, hOMasa->broadband_energy_sm_e ) ) + { + Scale_sig32( hOMasa->broadband_energy_sm_fx, nchan_all_inp, sub( hOMasa->broadband_energy_sm_e, max_broadband_energy_e ) ); + hOMasa->broadband_energy_sm_e = max_broadband_energy_e; + move16(); + } + ELSE + { + Scale_sig32( broadband_energy_fx, nchan_all_inp, sub( max_broadband_energy_e, hOMasa->broadband_energy_sm_e ) ); + max_broadband_energy_e = hOMasa->broadband_energy_sm_e; + move16(); } /* Temporal averaging */ - alpha = 0.8f; - for ( i = 0; i < nchan_all_inp; i++ ) + // alpha = 26214;/*0.8 Q15*/ + FOR( i = 0; i < nchan_all_inp; i++ ) { - hOMasa->broadband_energy_sm[i] = ( 1.0f - alpha ) * broadband_energy[i] + alpha * hOMasa->broadband_energy_sm[i]; + hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 ) ); + move32(); } /* Determine loudest object */ loudest_object = 0; - for ( i = 1; i < nchan_ism; i++ ) + move16(); + FOR( i = 1; i < nchan_ism; i++ ) { - if ( hOMasa->broadband_energy_sm[i] > hOMasa->broadband_energy_sm[loudest_object] ) + if ( GT_32( hOMasa->broadband_energy_sm_fx[i], hOMasa->broadband_energy_sm_fx[loudest_object] ) ) { loudest_object = i; + move16(); } } @@ -642,395 +675,205 @@ void ivas_omasa_enc( selected_object = hOMasa->prev_selected_object; fade_out_separate_object = 0; fade_in_separate_object = 0; - if ( hOMasa->changing_object ) + move16(); + move16(); + move16(); + IF( hOMasa->changing_object ) { hOMasa->changing_object = 0; selected_object = loudest_object; fade_in_separate_object = 1; + move16(); + move16(); + move16(); } - else + ELSE { - if ( loudest_object != hOMasa->prev_selected_object ) + IF( NE_16( loudest_object, hOMasa->prev_selected_object ) ) { - float selected_ene; - float total_ene; - float selected_ratio; - float adaptive_threshold_dB; - float ratio_objects_dB; - float hardswitch_threshold = 0.25f; + Word32 selected_ene_fx; /*selected_ene_e*/ + Word16 selected_ene_e; + Word32 total_ene_fx; /*total_ene_e*/ + Word16 total_ene_e; + Word32 selected_ratio_fx; /*selected_ratio_e*/ + Word16 selected_ratio_e; + Word32 adaptive_threshold_dB_fx; + Word32 ratio_objects_dB_fx; + Word32 hardswitch_threshold_fx; /*(0.25 q30) as selected_ratio_fx is in q30(both are compared later)*/ + Word16 temp32_e; + selected_ene_e = 0; + temp32_e = 0; + hardswitch_threshold_fx = 268435456; /*(0.25 q30)*/ + selected_ratio_e = 0; + total_ene_e = 0; + move16(); + move16(); + move16(); + move16(); + move32(); /* Compute the energy of the current and the previous selected object in the current and the previous frame */ - selected_ene = broadband_energy[loudest_object] + broadband_energy[hOMasa->prev_selected_object] + hOMasa->broadband_energy_prev[loudest_object] + hOMasa->broadband_energy_prev[hOMasa->prev_selected_object]; + /*scaling broadband_energy_fx and broadband_energy_prev_fx by 1 (guard bit for addition operation)*/ + selected_ene_fx = BASOP_Util_Add_Mant32Exp( L_add( L_shr( broadband_energy_fx[loudest_object], 1 ), L_shr( broadband_energy_fx[hOMasa->prev_selected_object], 1 ) ), add( max_broadband_energy_e, 1 ), L_add( L_shr( hOMasa->broadband_energy_prev_fx[loudest_object], 1 ), L_shr( hOMasa->broadband_energy_prev_fx[hOMasa->prev_selected_object], 1 ) ), add( hOMasa->broadband_energy_prev_e, 1 ), &selected_ene_e ); /* Compute the energy of all objects and MASA channels in the current and the previous frame */ - total_ene = 0.0f; - for ( i = 0; i < nchan_all_inp; i++ ) + total_ene_fx = 0; + move32(); + FOR( i = 0; i < nchan_all_inp; i++ ) { - total_ene += broadband_energy[i] + hOMasa->broadband_energy_prev[i]; + total_ene_fx = BASOP_Util_Add_Mant32Exp( total_ene_fx, total_ene_e, broadband_energy_fx[i], max_broadband_energy_e, &total_ene_e ); + total_ene_fx = BASOP_Util_Add_Mant32Exp( total_ene_fx, total_ene_e, hOMasa->broadband_energy_prev_fx[i], hOMasa->broadband_energy_prev_e, &total_ene_e ); } /* Compute the ratio */ - selected_ratio = selected_ene / ( total_ene + EPSILON ); - - adaptive_threshold_dB = selected_ratio * 9.0f + 1.0f; /* selected ratio = 0 -> 1 dB, selected ratio = 1 -> 10 dB */ - ratio_objects_dB = 10.0f * log10f( hOMasa->broadband_energy_sm[loudest_object] / ( hOMasa->broadband_energy_sm[hOMasa->prev_selected_object] + EPSILON ) ); + selected_ratio_fx = BASOP_Util_Divide3232_Scale( selected_ene_fx, L_add_sat( total_ene_fx, EPSILON_FX ), &selected_ratio_e ); + selected_ratio_e = add( selected_ratio_e, sub( selected_ene_e, total_ene_e ) ); + selected_ratio_fx = L_shl( selected_ratio_fx, add( selected_ratio_e, 15 ) ); /*scaling to q30 as the value will always be <=1*/ + adaptive_threshold_dB_fx = L_add( Mpy_32_16_1( selected_ratio_fx /*q30*/, 576 /*9 in q6*/ ), ONE_IN_Q21 ); /* selected ratio = 0 -> 1 dB, selected ratio = 1 -> 10 dB */ /*q21*/ + temp32 = BASOP_Util_Divide3232_Scale( hOMasa->broadband_energy_sm_fx[loudest_object], L_add_sat( hOMasa->broadband_energy_sm_fx[hOMasa->prev_selected_object], EPSILON_FX ), &temp32_e ); + ratio_objects_dB_fx = Mult_32_16( BASOP_Util_Log10( temp32, add( 16, temp32_e ) ) /*q25*/, 20480 /*10 in q11*/ ); /*q21 as the maximum value can go up to 320*/ /* Adaptively determine whether to change the separated object. If they are quiet compared to the total energy, change easier, as other signals mask the change. */ - if ( ratio_objects_dB > adaptive_threshold_dB ) + IF( GT_32( ratio_objects_dB_fx, adaptive_threshold_dB_fx ) ) { - if ( selected_ratio < hardswitch_threshold ) /* If low level compared to all audio channels, perform hardswitch */ + IF( LT_32( selected_ratio_fx, hardswitch_threshold_fx ) ) /* If low level compared to all audio channels, perform hardswitch */ { selected_object = loudest_object; + move16(); } - else /* If high level compared to all audio channels, perform switch via fade out fade in */ + ELSE /* If high level compared to all audio channels, perform switch via fade out fade in */ { hOMasa->changing_object = 1; fade_out_separate_object = 1; + move16(); + move16(); } } } } /* Set values for next frame */ - for ( i = 0; i < nchan_all_inp; i++ ) + FOR( i = 0; i < nchan_all_inp; i++ ) { - hOMasa->broadband_energy_prev[i] = broadband_energy[i]; + hOMasa->broadband_energy_prev_fx[i] = broadband_energy_fx[i]; + hOMasa->broadband_energy_prev_e = max_broadband_energy_e; + move32(); + move16(); } hOMasa->prev_selected_object = selected_object; + move16(); /* Separate the selected object */ *idx_separated_object = selected_object; - mvr2r( data_in_f[selected_object], data_separated_object, input_frame ); - if ( fade_out_separate_object ) + move16(); + Copy32( data_in[selected_object], data_separated_object_fx, input_frame ); + IF( fade_out_separate_object ) { - v_mult( data_separated_object, hOMasa->fade_out_gain, data_separated_object, input_frame ); - v_mult( data_in_f[selected_object], hOMasa->fade_in_gain, data_in_f[selected_object], input_frame ); + v_L_mult_3216( data_separated_object_fx, hOMasa->fade_out_gain_fx, data_separated_object_fx, input_frame ); /*q_data + q15 -q15*/ + v_L_mult_3216( data_in[selected_object], hOMasa->fade_in_gain_fx, data_in[selected_object], input_frame ); /*q_data + q15 -q15*/ } - else if ( fade_in_separate_object ) + ELSE IF( fade_in_separate_object ) { - v_mult( data_separated_object, hOMasa->fade_in_gain, data_separated_object, input_frame ); - v_mult( data_in_f[selected_object], hOMasa->fade_out_gain, data_in_f[selected_object], input_frame ); + v_L_mult_3216( data_separated_object_fx, hOMasa->fade_in_gain_fx, data_separated_object_fx, input_frame ); /*q_data + q15 -q15*/ + v_L_mult_3216( data_in[selected_object], hOMasa->fade_out_gain_fx, data_in[selected_object], input_frame ); /*q_data + q15 -q15*/ } - else + ELSE { - set_zero( data_in_f[selected_object], input_frame ); + set_zero_fx( data_in[selected_object], input_frame ); } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_ism; i++ ) - { - hIsmMeta[i]->azimuth_fx = float_to_fix( hIsmMeta[i]->azimuth, Q22 ); - hIsmMeta[i]->elevation_fx = float_to_fix( hIsmMeta[i]->elevation, Q22 ); - } - Word16 norm_data_in = MAX16B; - - for ( j = 0; j < nchan_ism; j++ ) - { - for ( int k = 0; k < input_frame; k++ ) - { - data_in[j][k] = float_to_fix( data_in_f[j][k], q_data ); - } - norm_data_in = s_min( norm_data_in, L_norm_arr( data_in[j], input_frame ) ); - } - norm_data_in -= 6; /*guard bit is 3->to handle overflow in cldfbAnalysis*/ - for ( j = 0; j < nchan_ism; j++ ) - { - Scale_sig32( data_in[j], input_frame, norm_data_in ); - } - q_data = q_data + norm_data_in; - for ( i = 0; i < nchan_ism; i++ ) - { - floatToFixed_arr32( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, q_data, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } -#endif /* Analysis */ - if ( ism_mode == ISM_MODE_NONE || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MODE_NONE ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { OMASA_SPATIAL_META OMasaMeta; /* working memory for the ISM-object MASA-parameters */ OMASA_SPATIAL_META_HANDLE hOMasaMeta; - uint8_t n_bands_orig, n_subframes_orig; - uint8_t numCodingBands_orig, joinedSubframes_orig; + UWord8 n_bands_orig, n_subframes_orig; + UWord8 numCodingBands_orig, joinedSubframes_orig; hOMasaMeta = &OMasaMeta; hOMasaMeta->num_dirs = 1; + move16(); /* merge MASA directions before adding ISM to the mixture */ - if ( hMasa->config.numberOfDirections == 2 ) + IF( EQ_16( hMasa->config.numberOfDirections, 2 ) ) { n_bands_orig = hMasa->config.numCodingBands; + move16(); hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 numCodingBands = hMasa->config.numCodingBands; - Word16 numDirections = hMasa->config.numberOfDirections; - Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; - MASA_METADATA_HANDLE hMeta; - hMeta = &( hMasa->masaMetadata ); - for ( i = 0; i < numDirections; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) - { - hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); - hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); - hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); - } - } - } - /* Combine directions on the remaining bands */ - for ( i = 0; i < hMasa->config.numCodingBands; i++ ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); - hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); - hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); - } - } - + move16(); /* Estimate the importance of having two directions instead of one */ - for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) - { - hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); - } -#endif - ivas_masa_combine_directions_fx( hMasa ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < numCodingBands; i++ ) - { - if ( hMasa->data.twoDirBands[i] == 0 ) - { - for ( j = 0; j < numSf; j++ ) - { - hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); - hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); - if ( computeCoherence ) - { - hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); - hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); - } - hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); - hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); - } - } - } -#endif -#else - ivas_masa_combine_directions( hMasa ); -#endif + ivas_masa_combine_directions_fx( hMasa ); - hMasa->config.numCodingBands = (int8_t) n_bands_orig; + hMasa->config.numCodingBands = (Word8) n_bands_orig; + move16(); } /* force computation into high resolution */ n_subframes_orig = hOMasa->nSubframes; hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + move16(); /* Estimate MASA parameters from the objects */ /* NB: only first direction is populated */ /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ ivas_omasa_param_est_enc_fx( hOMasa, hMasa->data.hOmasaData, hIsmMeta, data_in, hOMasaMeta->directional_meta[0].elevation_fx, hOMasaMeta->directional_meta[0].azimuth_fx, hOMasaMeta->directional_meta[0].energy_ratio_fx[0], hOMasaMeta->directional_meta[0].spread_coherence_fx, hOMasaMeta->common_meta.surround_coherence_fx[0], hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[0], input_frame, nchan_ism, q_data ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - Word16 block_m_idx, band_m_idx; - for ( i = 0; i < nchan_ism; i++ ) - { - fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, q_data, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 32; j++ ) - { - for ( int k = 0; k < MASA_FREQUENCY_BANDS; k++ ) - { - hOMasa->buffer_intensity_real[i][j][k] = fixedToFloat( hOMasa->buffer_intensity_real_fx[i][j][k], hOMasa->buffer_intensity_real_q[j] ); - } - } - } - for ( i = 0; i < DIRAC_NO_COL_AVG_DIFF; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hOMasa->buffer_energy[i * MASA_FREQUENCY_BANDS + j] = fixedToFloat( hOMasa->buffer_energy_fx[i * MASA_FREQUENCY_BANDS + j], hOMasa->buffer_energy_q[i] ); - } - } - FOR( i = 0; i < nchan_ism; i++ ) - { - hOMasa->chnlToFoaMtx[0][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[0][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[1][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[1][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[2][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[2][i], 31 ); /*q31*/ - hOMasa->chnlToFoaMtx[3][i] = fixedToFloat( hOMasa->chnlToFoaMtx_fx[3][i], 31 ); /*q31*/ - } - for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hMasa->data.hOmasaData->energy_ism[block_m_idx][band_m_idx] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][band_m_idx], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][band_m_idx] ); - hOMasaMeta->directional_meta[0].spread_coherence[block_m_idx][band_m_idx] = fixedToFloat( hOMasaMeta->directional_meta[0].spread_coherence_fx[block_m_idx][band_m_idx], Q15 ); - hOMasaMeta->common_meta.surround_coherence[0][band_m_idx] = fixedToFloat( hOMasaMeta->common_meta.surround_coherence_fx[0][band_m_idx], Q15 ); - hOMasaMeta->directional_meta[0].azimuth[block_m_idx][band_m_idx] = fixedToFloat( hOMasaMeta->directional_meta[0].azimuth_fx[block_m_idx][band_m_idx], Q22 ); - hOMasaMeta->directional_meta[0].elevation[block_m_idx][band_m_idx] = fixedToFloat( hOMasaMeta->directional_meta[0].elevation_fx[block_m_idx][band_m_idx], Q22 ); - hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[0][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[1][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = fixedToFloat( hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx], sub( 31, hOMasa->direction_vector_e[2][block_m_idx][band_m_idx] ) ); /*q_diffuseness_vector+(31-ref_exp)-31-1*/ - } - } - for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) - { - hOMasaMeta->common_meta.diffuse_to_total_ratio[0][band_m_idx] = fixedToFloat( hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[0][band_m_idx], Q30 ); - hOMasaMeta->directional_meta[0].energy_ratio[0][band_m_idx] = fixedToFloat( hOMasaMeta->directional_meta[0].energy_ratio_fx[0][band_m_idx], Q30 ); - } -#endif // DEBUG /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ - for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { -#ifdef IVAS_FLOAT_FIXED - Copy32( hOMasaMeta->directional_meta[0].energy_ratio_fx[0], hOMasaMeta->directional_meta[0].energy_ratio_fx[i], MASA_FREQUENCY_BANDS ); - Copy( hOMasaMeta->common_meta.surround_coherence_fx[0], hOMasaMeta->common_meta.surround_coherence_fx[i], MASA_FREQUENCY_BANDS ); - Copy32( hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[0], hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[i], MASA_FREQUENCY_BANDS ); -#endif // IVAS_FLOAT_FIXED - mvr2r( hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].energy_ratio[i], MASA_FREQUENCY_BANDS ); - mvr2r( hOMasaMeta->common_meta.surround_coherence[0], hOMasaMeta->common_meta.surround_coherence[i], MASA_FREQUENCY_BANDS ); - mvr2r( hOMasaMeta->common_meta.diffuse_to_total_ratio[0], hOMasaMeta->common_meta.diffuse_to_total_ratio[i], MASA_FREQUENCY_BANDS ); + Copy32( hOMasaMeta->directional_meta[0].energy_ratio_fx[0], hOMasaMeta->directional_meta[0].energy_ratio_fx[i], MASA_FREQUENCY_BANDS ); /*q30*/ + Copy( hOMasaMeta->common_meta.surround_coherence_fx[0], hOMasaMeta->common_meta.surround_coherence_fx[i], MASA_FREQUENCY_BANDS ); /*q14*/ + Copy32( hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[0], hOMasaMeta->common_meta.diffuse_to_total_ratio_fx[i], MASA_FREQUENCY_BANDS ); /*q30*/ } /* restore resolution parameters */ hOMasa->nSubframes = n_subframes_orig; + move16(); /* perform MASA+ISM merge in full resolution */ numCodingBands_orig = hMasa->config.numCodingBands; joinedSubframes_orig = hMasa->config.joinedSubframes; + move16(); + move16(); hMasa->config.numCodingBands = hOMasa->nbands; hMasa->config.joinedSubframes = 0; + move16(); + move16(); -#if 1 - int16_t numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - for ( i = 0; i < numSf; i++ ) - { - for ( j = 0; j < hMasa->config.numCodingBands; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j], 30 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j], 30 ); - hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].azimuth[i][j], 22 ); - hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[1].elevation[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].azimuth[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j] = float_to_fix( hMasa->masaMetadata.directional_meta[0].elevation[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j], 15 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j], 15 ); - hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j] = float_to_fix16( hMasa->masaMetadata.common_meta.surround_coherence[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j] = float_to_fix( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j], 30 ); - } - } ivas_merge_masa_metadata_fx( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ - for ( i = 0; i < numSf; i++ ) - { - for ( j = 0; j < hMasa->config.numCodingBands; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - hMasa->masaMetadata.directional_meta[0].energy_ratio[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[0].energy_ratio_fx[i][j], 30 ); - hMasa->masaMetadata.directional_meta[1].energy_ratio[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[1].energy_ratio_fx[i][j], 30 ); - hMasa->masaMetadata.directional_meta[1].azimuth[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[1].azimuth_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[1].elevation[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[1].elevation_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].azimuth[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[0].azimuth_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].elevation[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[0].elevation_fx[i][j], 22 ); - hMasa->masaMetadata.directional_meta[0].spread_coherence[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[0].spread_coherence_fx[i][j], 15 ); - hMasa->masaMetadata.directional_meta[1].spread_coherence[i][j] = fix_to_float( hMasa->masaMetadata.directional_meta[1].spread_coherence_fx[i][j], 15 ); - hMasa->masaMetadata.common_meta.surround_coherence[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.surround_coherence_fx[i][j], 15 ); - hMasa->masaMetadata.common_meta.diffuse_to_total_ratio[i][j] = fix_to_float( hMasa->masaMetadata.common_meta.diffuse_to_total_ratio_fx[i][j], 30 ); - } - } -#else - ivas_merge_masa_metadata( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ -#endif hMasa->config.numCodingBands = numCodingBands_orig; hMasa->config.joinedSubframes = joinedSubframes_orig; + move16(); + move16(); } - else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { /* Estimate energies and ratios */ -#ifdef IVAS_FLOAT_FIXED ivas_omasa_energy_and_ratio_est_fx( hOMasa, hMasa->data.hOmasaData, data_in, input_frame, nchan_ism, q_data ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for ( i = 0; i < nchan_ism; i++ ) - { - fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, q_data, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); - } - for ( int block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) - { - for ( i = 0; i < hOMasa->nbands; i++ ) - { - for ( int k = 0; k < nchan_ism; k++ ) - { - hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = me2f( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], 1 ); - } - hMasa->data.hOmasaData->energy_ism[block_m_idx][i] = me2f( hMasa->data.hOmasaData->energy_ism_fx[block_m_idx][i], hMasa->data.hOmasaData->energy_ism_fx_e[block_m_idx][i] ); - } - } -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED -#else - ivas_omasa_energy_and_ratio_est( hOMasa, hMasa->data.hOmasaData, data_in_f, input_frame, nchan_ism ); -#endif // IVAS_FLOAT_FIXED } /* Downmix */ -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for ( j = 0; j < nchan_ism; j++ ) - { - for ( int k = 0; k < input_frame; k++ ) - { - data_in[j][k] = float_to_fix( data_in_f[j][k], q_data ); - } - } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains_fx[i][j] = float_to_fix16( hOMasa->prev_object_dm_gains[i][j], 15 ); - } - } - for ( i = 0; i < input_frame; i++ ) - { - hOMasa->interpolator_fx[i] = float_to_fix16( hOMasa->interpolator[i], 15 ); - } - FOR( i = 0; i < nchan_ism; i++ ) - { - hIsmMeta[i]->azimuth_fx = float_to_fix( hIsmMeta[i]->azimuth, Q22 ); - hIsmMeta[i]->elevation_fx = float_to_fix( hIsmMeta[i]->elevation, Q22 ); - } -#endif // IVAS_FLOAT_FIXED_TO_BE_REMOVED - ivas_omasa_dmx_fx( data_in, data_out, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - for ( i = 0; i < nchan_transport; i++ ) - { - fixedToFloat_arrL( data_out[i], data_out_f[i], q_data, input_frame ); - } - for ( i = 0; i < nchan_ism; i++ ) - { - for ( j = 0; j < nchan_transport; j++ ) - { - hOMasa->prev_object_dm_gains[i][j] = fixedToFloat( hOMasa->prev_object_dm_gains_fx[i][j], 15 ); - } - } -#endif + ivas_omasa_dmx_fx( data_in, data_out, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains_fx, hOMasa->interpolator_fx ); /* Move the ISM metadata to the first entry for encoding in the MASA_ONE_OBJ mode */ - if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - hIsmMeta[0]->azimuth = hIsmMeta[*idx_separated_object]->azimuth; - hIsmMeta[0]->elevation = hIsmMeta[*idx_separated_object]->elevation; + hIsmMeta[0]->azimuth_fx = hIsmMeta[*idx_separated_object]->azimuth_fx; + hIsmMeta[0]->elevation_fx = hIsmMeta[*idx_separated_object]->elevation_fx; + move32(); + move32(); } /* Merge transport signals */ - ivas_merge_masa_transports( data_out_f, &( data_in_f[nchan_ism] ), data_in_f, input_frame, nchan_transport ); + ivas_merge_masa_transports_fx( data_out, &( data_in[nchan_ism] ), data_in, input_frame, nchan_transport ); return; } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 86b41c04d..3247cdf34 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -1592,45 +1592,42 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( /*! r: number of bits written */ #ifdef IVAS_FLOAT_FIXED -void ivas_qmetadata_enc_sid_encode( - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ - const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure */ - const int16_t ivas_format /* i : IVAS format */ +void ivas_qmetadata_enc_sid_encode_fx( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ + const Word16 masa_sid_descriptor, /* i : description of MASA SID coding structure */ + const Word16 ivas_format /* i : IVAS format */ ) { - int16_t b, m; - int16_t bit_pos_start; + Word16 b, m; + Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; - int16_t nbands, nblocks, start_band; - float avg_direction_vector[3]; - float direction_vector[3]; - float avg_azimuth[MASA_MAXIMUM_CODING_SUBBANDS]; - float avg_elevation[MASA_MAXIMUM_CODING_SUBBANDS]; -#ifdef IVAS_FLOAT_FIXED - // Word32 avg_direction_vector_fx[3]; + Word16 nbands, nblocks, start_band; + Word32 avg_direction_vector_fx[3]; + Word32 avg_elevation_fx[MASA_MAXIMUM_CODING_SUBBANDS]; Word32 direction_vector_fx[3]; - // Word32 avg_azimuth_fx[MASA_MAXIMUM_CODING_SUBBANDS]; - // Word32 avg_elevation_fx[MASA_MAXIMUM_CODING_SUBBANDS]; -#endif - int16_t bits_dir, bits_diff, bits_delta; - int16_t metadata_sid_bits; /* bits allocated to SID for metadata */ + Word32 avg_azimuth_fx[MASA_MAXIMUM_CODING_SUBBANDS]; + Word16 bits_dir, bits_diff, bits_delta; + Word16 metadata_sid_bits; /* bits allocated to SID for metadata */ - if ( ivas_format == SBA_FORMAT ) + IF( EQ_16( ivas_format, SBA_FORMAT ) ) { - metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ + metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ + move16(); } - else + ELSE { metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + move16(); } /* Save initial position in bitstream */ bit_pos_start = hMetaData->nb_bits_tot; + move16(); /* write for MASA the number of transport channels used at coding and the CPE mode DFT/MDCT */ - if ( masa_sid_descriptor > -1 ) + IF( GT_16( masa_sid_descriptor, negate( 1 ) ) ) { push_next_indice( hMetaData, masa_sid_descriptor, 1 ); } @@ -1639,126 +1636,143 @@ void ivas_qmetadata_enc_sid_encode( q_direction = &( q_metadata->q_direction[0] ); nbands = q_direction->cfg.nbands; nblocks = q_direction->cfg.nblocks; + move16(); + move16(); start_band = 0; /*Start always with band 0 for SID*/ + move16(); /* sanity checks*/ assert( q_metadata->no_directions == 1 && "Qmetadata SID: only one direction supported!" ); - if ( ivas_format == SBA_FORMAT ) + IF( EQ_16( ivas_format, SBA_FORMAT ) ) { assert( ( q_direction->cfg.nbands == DIRAC_DTX_BANDS ) && "Qmetadata SID: only 2 bands supported!" ); } - else + ELSE { assert( ( q_direction->cfg.nbands == 5 ) && "Qmetadata SID: only 5 bands supported!" ); } - if ( ivas_format != SBA_FORMAT ) + IF( NE_16( ivas_format, SBA_FORMAT ) ) { /* Signalling 2D*/ push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ } - else + ELSE { q_direction->not_in_2D = 1; /* force for merged modes */ + move16(); } /*Encode the quantized diffuseness in raw coding*/ bits_dir = 0; bits_diff = 0; - if ( ivas_format != SBA_FORMAT ) + move16(); + move16(); + IF( NE_16( ivas_format, SBA_FORMAT ) ) { - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); - bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].energy_ratio_index[0] = s_max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + move16(); + bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; + move16(); - if ( q_direction->not_in_2D == 0 ) + IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); - bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + move16(); + bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } - else + ELSE { - bits_dir += q_direction->band_data[b].bits_sph_idx[0]; + bits_dir = add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ); } } /* Reduce bit demand by increasing diffuseness*/ - bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; - if ( bits_delta > 0 ) + bits_delta = sub( sub( sub( metadata_sid_bits, sub( hMetaData->nb_bits_tot, bit_pos_start ) ), bits_diff ), bits_dir ); + IF( bits_delta > 0 ) { - while ( bits_delta > 0 ) + WHILE( bits_delta > 0 ) { - for ( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) + FOR( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) { - if ( q_direction->band_data[b].bits_sph_idx[0] < 11 ) + IF( LT_16( q_direction->band_data[b].bits_sph_idx[0], 11 ) ) { - bits_delta -= 1; - q_direction->band_data[b].bits_sph_idx[0]++; + bits_delta = sub( bits_delta, 1 ); + q_direction->band_data[b].bits_sph_idx[0] = add( q_direction->band_data[b].bits_sph_idx[0], 1 ); + move16(); } } } - if ( q_direction->not_in_2D == 0 ) + IF( q_direction->not_in_2D == 0 ) { - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + move16(); } } } - else + ELSE { - while ( bits_delta < 0 ) + WHILE( bits_delta < 0 ) { - for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { - if ( q_direction->band_data[b].bits_sph_idx[0] >= 4 ) + IF( GE_16( q_direction->band_data[b].bits_sph_idx[0], 4 ) ) { - bits_delta += 1; - q_direction->band_data[b].bits_sph_idx[0]--; - if ( q_direction->not_in_2D == 0 ) + bits_delta = add( bits_delta, 1 ); + q_direction->band_data[b].bits_sph_idx[0] = sub( q_direction->band_data[b].bits_sph_idx[0], 1 ); + IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + move16(); } } } } } } - else + ELSE { - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); - bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].energy_ratio_index[0] = s_max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; + move16(); - if ( q_direction->not_in_2D == 0 ) + IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); - bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + move16(); + bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } - else + ELSE { - bits_dir += q_direction->band_data[b].bits_sph_idx[0]; + bits_dir = add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ); } } /* Reduce bit demand by increasing diffuseness*/ - bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; + bits_delta = sub( sub( sub( metadata_sid_bits, sub( hMetaData->nb_bits_tot, bit_pos_start ) ), bits_diff ), bits_dir ); - while ( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) + test(); + WHILE( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) { - for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { - if ( q_direction->band_data[b].energy_ratio_index[0] < ( DIRAC_DIFFUSE_LEVELS - 1 ) ) + IF( LT_16( q_direction->band_data[b].energy_ratio_index[0], ( DIRAC_DIFFUSE_LEVELS - 1 ) ) ) { - bits_delta += q_direction->band_data[b].bits_sph_idx[0]; - q_direction->band_data[b].energy_ratio_index[0]++; + bits_delta = add( bits_delta, q_direction->band_data[b].bits_sph_idx[0] ); + q_direction->band_data[b].energy_ratio_index[0] = add( q_direction->band_data[b].energy_ratio_index[0], 1 ); + move16(); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - bits_delta -= q_direction->band_data[b].bits_sph_idx[0]; + move16(); + bits_delta = sub( bits_delta, q_direction->band_data[b].bits_sph_idx[0] ); } } } @@ -1766,86 +1780,66 @@ void ivas_qmetadata_enc_sid_encode( assert( ( bits_delta >= 0 ) && "Bit budget in Qmetadata SID is violated!!!" ); /*Code diffuseness*/ - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ); } /* Compute and Quantize an average direction per band*/ - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { - set_zero( avg_direction_vector, 3 ); - for ( m = 0; m < nblocks; m++ ) + set32_fx( avg_direction_vector_fx, 0, 3 ); + FOR( m = 0; m < nblocks; m++ ) { /*compute the average direction */ -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[b].azimuth[m], q_direction->band_data[b].elevation[m], direction_vector ); -#endif - v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + FOR( int i = 0; i < 3; i++ ) + { + avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); + move32(); + } } -#ifdef IVAS_FLOAT_FIXED_ - /*==========================================flt-2-fix======================================================*/ - Word16 q_dir_e = 0; - f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); - Scale_sig32( avg_direction_vector_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); - /*==========================================fix-2-flt======================================================*/ - avg_azimuth[b] = fixedToFloat( avg_azimuth_fx[b], Q22 ); - avg_elevation[b] = fixedToFloat( avg_elevation_fx[b], Q22 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth[b], &avg_elevation[b] ); -#endif - /* Quantize the average direction */ - if ( q_direction->not_in_2D == 0 ) + IF( q_direction->not_in_2D == 0 ) { - avg_elevation[b] = 0; - q_direction->band_data[b].spherical_index[0] = quantize_direction2D( avg_azimuth[b], q_direction->band_data[b].azimuth_m_alphabet[0], &avg_azimuth[b], - &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].spherical_index[0] = quantize_direction2D_fx( avg_azimuth_fx[b], q_direction->band_data[b].azimuth_m_alphabet[0], &avg_azimuth_fx[b], + &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + move16(); } - else + ELSE { - q_direction->band_data[b].spherical_index[0] = quantize_direction( avg_elevation[b], avg_azimuth[b], q_direction->band_data[b].bits_sph_idx[0], &avg_elevation[b], &avg_azimuth[b], - &q_direction->band_data[b].elevation_index[0], &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].spherical_index[0] = quantize_direction_fx( avg_elevation_fx[b], avg_azimuth_fx[b], q_direction->band_data[b].bits_sph_idx[0], &avg_elevation_fx[b], &avg_azimuth_fx[b], + &q_direction->band_data[b].elevation_index[0], &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + move16(); } /* Save quantized DOAs */ - q_direction->band_data[b].q_azimuth[0] = avg_azimuth[b]; - q_direction->band_data[b].q_elevation[0] = avg_elevation[b]; + q_direction->band_data[b].q_azimuth_fx[0] = avg_azimuth_fx[b]; + q_direction->band_data[b].q_elevation_fx[0] = avg_elevation_fx[b]; + move32(); + move32(); - if ( q_direction->band_data[b].azimuth_index[0] == MASA_NO_INDEX ) + IF( EQ_16( q_direction->band_data[b].azimuth_index[0], MASA_NO_INDEX ) ) { q_direction->band_data[b].azimuth_index[0] = 0; + move16(); } } /* quantize average elevation and azimuth angles */ - if ( q_direction->not_in_2D > 0 ) + IF( q_direction->not_in_2D > 0 ) { - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { push_next_indice( hMetaData, q_direction->band_data[b].spherical_index[0], q_direction->band_data[b].bits_sph_idx[0] ); } } - else + ELSE { - for ( b = start_band; b < nbands; b++ ) + FOR( b = start_band; b < nbands; b++ ) { ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); } @@ -1854,7 +1848,7 @@ void ivas_qmetadata_enc_sid_encode( /* fill bits*/ assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); - while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits ) + WHILE( LT_16( ( sub( hMetaData->nb_bits_tot, bit_pos_start ) ), metadata_sid_bits ) ) { push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ } @@ -2230,7 +2224,6 @@ Word16 quantize_direction2D_fx( } #endif -/*! r: quantized spherical index */ int16_t quantize_direction2D( float phi, /* i : input azimuth value */ const int16_t no_cw, /* i : number of bits */ diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 8ed19413e..e27f432be 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -290,8 +290,14 @@ ivas_error ivas_sce_enc( if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { +#ifndef IVAS_FLOAT_FIXED ivas_set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); - +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = 0; +#endif + ivas_set_ism_importance_interformat_fx( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx, &st_ivas->hIsmMetaData[0]->ism_imp ); +#endif #ifndef IVAS_FLOAT_FIXED st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; #else diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 62d220da1..2cabcf9fd 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1143,7 +1143,13 @@ typedef struct ivas_omasa_enc_state_structure Word32 buffer_energy_fx[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; Word16 buffer_intensity_real_q[DIRAC_NO_COL_AVG_DIFF]; Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF]; -#endif // IVAS_FLOAT_FIXED + Word32 broadband_energy_sm_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + Word16 broadband_energy_sm_e; + Word32 broadband_energy_prev_fx[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + Word16 broadband_energy_prev_e; + Word16 fade_out_gain_fx[L_FRAME48k]; /*q15*/ + Word16 fade_in_gain_fx[L_FRAME48k]; /*q15*/ +#endif // IVAS_FLOAT_FIXED uint8_t nbands; uint8_t nCodingBands; uint8_t nSubframes; @@ -1248,8 +1254,14 @@ typedef struct ivas_masa_encoder_data_struct #endif int16_t prevq_lfeIndex; +#ifndef IVAS_FLOAT_FIXED float onset_detector_1; float onset_detector_2; +#else + Word32 onset_detector_1_fx; + Word32 onset_detector_2_fx; + Word16 q_onset_detector; +#endif MASA_SYNC_STATE sync_state; @@ -1281,7 +1293,7 @@ typedef struct ivas_mcmasa_enc_data_structure #ifndef IVAS_FLOAT_FIXED float *delay_buffer_lfe[2]; /* Delay buffer for LFE estimation */ #else - Word32 *delay_buffer_lfe[2]; /* Delay buffer for LFE estimation */ + Word32 *delay_buffer_lfe[2]; /* Delay buffer for LFE estimation */ #endif int16_t num_samples_delay_comp; @@ -1295,7 +1307,7 @@ typedef struct ivas_mcmasa_enc_data_structure #ifndef IVAS_FLOAT_FIXED float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ #else - Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ #endif Word16 **direction_vector_e[DIRAC_NUM_DIMS]; /* Average direction vector */ int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; diff --git a/lib_enc/plc_enc_ext.c b/lib_enc/plc_enc_ext.c index 2577539c6..3928a40a8 100644 --- a/lib_enc/plc_enc_ext.c +++ b/lib_enc/plc_enc_ext.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED #define NBITS_GACELP 5 /*-------------------------------------------------------------------* @@ -134,3 +135,4 @@ void gPLC_encInfo( return; } +#endif diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index d9fb96f24..571636031 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -190,11 +190,11 @@ typedef struct TransientDetector int16_t nSubblocksToCheck; /* Number of subblocks to check for transients. */ TCheckSubblocksForAttack CheckSubblocksForAttack; /* Function for checking a presence of an attack. */ TCheckSubblocksForAttack_fx CheckSubblocksForAttack_fx; /* Function for checking a presence of an attack. */ - float attackRatioThreshold_flt; /* Attack ratio threshold. */ - Word16 attackRatioThreshold; - int16_t bIsAttackPresent; /* True when an attack was detected. */ - int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ - int16_t attackIndex; /* The index of an attack. */ + float attackRatioThreshold_flt; /* Attack ratio threshold */ + Word16 attackRatioThreshold; /* Attack ratio threshold Q11 */ + int16_t bIsAttackPresent; /* True when an attack was detected. */ + int16_t prev_bIsAttackPresent; /* True if an attack was detected in the previous frame. */ + int16_t attackIndex; /* The index of an attack. */ } TransientDetector; /* Transient detection: Holds all transient detectors and buffers used by them. */ @@ -1464,14 +1464,14 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; #else - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ #endif float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; #ifndef IVAS_FLOAT_FIXED float cldfbHBLT_flt; #else - Word16 cldfbHBLT; /* Q13 */ + Word16 cldfbHBLT; /* Q13 */ #endif /* states for the filters used in generating SHB excitation from WB excitation*/ float mem_csfilt[2]; @@ -1483,22 +1483,22 @@ typedef struct td_bwe_enc_structure Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ #ifndef IVAS_FLOAT_FIXED float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ + float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ #else - Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ -#endif - float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ - Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ + Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ + Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; - float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ Word16 prev_shb_env_tilt_q; +#endif float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ #ifndef IVAS_FLOAT_FIXED float prev_mix_factor; /* mixing factor in the previous frame */ #else - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ #endif float prev_Env_error; /* error in SHB envelope modelling */ Word16 prev_Env_error_fx; /* error in SHB envelope modelling */ @@ -1511,37 +1511,43 @@ typedef struct td_bwe_enc_structure Word16 state_lpc_syn_fx[LPC_SHB_ORDER]; /* Q(prev_Q_bwe_exc - 16) */ Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; +#ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; +#else + Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ +#endif float old_bwe_exc_extended[NL_BUFF_OFFSET]; - float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + float syn_overlap[L_SHB_LAHEAD]; /* overlap buffer used to Adjust SHB Frame Gain*/ + Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ + Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* Q0 not sure */ +#ifndef IVAS_FLOAT_FIXED float decim_state1[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float decim_state2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; +#else + Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ + Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ +#endif float mem_genSHBexc_filt_down_wb2[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_wb3[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; float mem_genSHBexc_filt_down_shb[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; - Word32 bwe_non_lin_prev_scale_fx; /* Q30 */ - Word16 old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; /* Q(prev_Q_bwe_exc - 16) */ - Word16 syn_overlap_fx[L_SHB_LAHEAD]; /* Q0 not sure */ - Word16 decim_state1_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ - Word16 decim_state2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(-1) */ Word16 mem_genSHBexc_filt_down_wb2_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_wb3_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ Word16 mem_genSHBexc_filt_down_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* Q(prev_Q_bwe_exc - 16) */ +#ifndef IVAS_FLOAT_FIXED float elliptic_bpf_2_48k_mem[4][4]; float prev_fb_energy; - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /*elliptic_bpf_2_48k_mem_fx_Q[4]*/ - Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; - Word32 prev_fb_energy_fx; /*prev_fb_energy_fx_Q*/ - Word16 prev_fb_energy_fx_Q; -#ifndef IVAS_FLOAT_FIXED float prev_gainFr_SHB; float lsp_shb_slow_interpl[LPC_SHB_ORDER]; float lsp_shb_fast_interpl[LPC_SHB_ORDER]; #else - Word32 prev_gainFr_SHB_fx; /* Q18 */ - Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ - Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /* Q(elliptic_bpf_2_48k_mem_fx_Q[4]) */ + Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; + Word32 prev_fb_energy_fx; /* Q(prev_fb_energy_fx_Q) */ + Word16 prev_fb_energy_fx_Q; + Word32 prev_gainFr_SHB_fx; /* Q18 */ + Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ #endif float shb_inv_filt_mem[LPC_SHB_ORDER]; Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; @@ -1549,8 +1555,8 @@ typedef struct td_bwe_enc_structure float lsp_shb_spacing[3]; float prev_swb_GainShape; #else - Word16 lsp_shb_spacing_fx[3]; /* Q15 */ - Word16 prev_swb_GainShape_fx; /* Q15 */ + Word16 lsp_shb_spacing_fx[3]; /* Q15 */ + Word16 prev_swb_GainShape_fx; /* Q15 */ #endif int16_t prev_frGainAtten; @@ -1559,8 +1565,8 @@ typedef struct td_bwe_enc_structure float prev_wb_GainShape_flt; float swb_lsp_prev_interp[LPC_SHB_ORDER]; #else - Word16 prev_wb_GainShape; /* Q15 */ - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 prev_wb_GainShape; /* Q15 */ + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ #endif float fb_state_lpc_syn[LPC_SHB_ORDER]; float fb_tbe_demph; @@ -1570,7 +1576,7 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float tilt_mem; #else - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1578,8 +1584,8 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ - Word16 prev_tilt_para_fx; /* Q10 */ + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ + Word16 prev_tilt_para_fx; /* Q10 */ #endif float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ @@ -1627,14 +1633,17 @@ typedef struct fd_bwe_enc_structure { float new_input_hp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; float old_input[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; + Word16 new_input_hp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; + Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; +#ifndef IVAS_FLOAT_FIXED float old_input_wb[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; +#else + Word16 old_input_wb_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /* Q(-1) */ +#endif float old_input_lp[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; float old_fdbwe_speech[L_FRAME48k]; float mem_deemph_old_syn; - Word16 new_input_hp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS )]; - Word16 old_input_fx[NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS )]; - Word16 old_input_wb_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; /* Q(-1) */ Word16 old_input_lp_fx[NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS )]; Word16 old_syn_12k8_16k_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; Word16 old_fdbwe_speech_fx[L_FRAME48k]; @@ -1644,13 +1653,19 @@ typedef struct fd_bwe_enc_structure Word16 L_old_wtda_swb_fx[L_FRAME48k]; /* Q(Q_old_wtda) */ Word16 prev_Q_input_lp; int16_t prev_L_swb_norm1; +#ifndef IVAS_FLOAT_FIXED float prev_global_gain; - Word32 prev_global_gain_fx; +#else + Word32 prev_global_gain_fx; /* Q(2 * prev_Q_shb) */ +#endif int16_t modeCount; +#ifndef IVAS_FLOAT_FIXED float EnergyLF; - Word32 EnergyLF_fx; float mem_old_wtda_swb; +#else + Word32 EnergyLF_fx; Word16 mem_old_wtda_swb_fx; /* Q(-1) */ +#endif } FD_BWE_ENC_DATA, *FD_BWE_ENC_HANDLE; @@ -1727,35 +1742,50 @@ typedef struct plc_enc_evs_structure int16_t pit_min; int16_t pit_max; +#ifndef IVAS_FLOAT_FIXED float mem_MA[M]; float mem_AR_flt[M]; +#else Word16 mem_MA_14Q1[M]; Word16 mem_AR[M]; +#endif - float lsfold[M]; /* old lsf (frequency domain) */ - float lspold[M]; /* old lsp (immittance spectral pairs) */ - Word16 lsfold_14Q1[M]; /* old lsf (frequency domain) */ - Word16 lspold_Q15[M]; /* old lsp (immittance spectral pairs) */ +#ifndef IVAS_FLOAT_FIXED + float lsfold[M]; /* old lsf (frequency domain) */ + float lspold[M]; /* old lsp (immittance spectral pairs) */ +#else + Word16 lsfold_14Q1[M]; /* old lsf (frequency domain) */ + Word16 lspold_Q15[M]; /* old lsp (immittance spectral pairs) */ +#endif - float lsfoldbfi0[M]; /* Previous frame lsf */ - float lsfoldbfi1[M]; /* Past previous frame lsf */ +#ifndef IVAS_FLOAT_FIXED + float lsfoldbfi0[M]; /* Previous frame lsf */ + float lsfoldbfi1[M]; /* Past previous frame lsf */ + float lsf_adaptive_mean[M]; /* Mean lsf for bfi cases */ + float stab_fac; +#else Word16 lsfoldbfi0_14Q1[M]; /* Previous frame LSF */ Word16 lsfoldbfi1_14Q1[M]; /* Past previous frame LSF */ - float lsf_adaptive_mean[M]; /* Mean lsf for bfi cases */ Word16 lsf_adaptive_mean_14Q1[M]; /* Mean isf for bfi cases */ - float stab_fac; Word16 stab_fac_Q15; +#endif LPD_state *LPDmem; - float old_exc[8]; /* ACELP exc memory (Aq) */ +#ifndef IVAS_FLOAT_FIXED + float old_exc[8]; /* ACELP exc memory (Aq) */ +#else Word16 old_exc_Qold[8]; /* ACELP exc memory (Aq)*/ +#endif +#ifndef IVAS_FLOAT_FIXED float lsf_con_flt[M]; float last_lsf_ref_flt[M]; float last_lsf_con_flt[M]; +#else Word16 lsf_con[M]; Word16 last_lsf_ref[M]; Word16 last_lsf_con[M]; +#endif } PLC_ENC_EVS, *PLC_ENC_EVS_HANDLE; @@ -1766,14 +1796,17 @@ typedef struct plc_enc_evs_structure typedef struct tec_enc_structure { +#ifndef IVAS_FLOAT_FIXED float loBuffer_flt[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; float loTempEnv_flt[CLDFB_NO_COL_MAX]; float loTempEnv_ns_flt[CLDFB_NO_COL_MAX]; float hiTempEnv_flt[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; - Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; - Word16 loTempEnv[CLDFB_NO_COL_MAX]; - Word16 loTempEnv_ns[CLDFB_NO_COL_MAX]; - Word16 hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; +#else + Word16 loBuffer[CLDFB_NO_COL_MAX + MAX_TEC_SMOOTHING_DEG + DELAY_TEMP_ENV_BUFF_TEC]; /* Q8 */ + Word16 loTempEnv[CLDFB_NO_COL_MAX]; /* Q7 */ + Word16 loTempEnv_ns[CLDFB_NO_COL_MAX]; /* Q7 */ + Word16 hiTempEnv[CLDFB_NO_COL_MAX + DELAY_TEMP_ENV_BUFF_TEC + EXT_DELAY_HI_TEMP_ENV]; /* Q7 */ +#endif int16_t tranFlag; int16_t corrFlag; @@ -2003,8 +2036,8 @@ typedef struct enc_core_structure float prev_fmerit_flt; /* previous signal classification score*/ float fmerit_dt_flt; /* signal classification score difference */ #else - Word16 prev_fmerit; /* previous signal classification score Q15 */ - Word16 fmerit_dt; /* signal classification score difference Q15 */ + Word16 prev_fmerit; /* previous signal classification score Q15 */ + Word16 fmerit_dt; /* signal classification score difference Q15 */ #endif int16_t Nb_ACELP_frames; @@ -2101,7 +2134,7 @@ typedef struct enc_core_structure #ifndef IVAS_FLOAT_FIXED float old_thres; /* normalized correlation weighting in open-loop pitch */ #else - Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ + Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ #endif float old_corr; /* normalized correlation in previous frame (mean value) */ Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ @@ -2251,7 +2284,7 @@ typedef struct enc_core_structure #ifndef IVAS_FLOAT_FIXED float bckr_tilt_lt_flt; #else - Word32 bckr_tilt_lt; /* Q16 */ + Word32 bckr_tilt_lt; /* Q16 */ #endif float lp_speech; float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ @@ -2294,8 +2327,8 @@ typedef struct enc_core_structure float last_totalNoise; float totalNoise_increase_hist[TOTALNOISE_HIST_SIZE]; #else - Word16 last_totalNoise_fx; /* Q8 */ - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; /* Q8 */ + Word16 last_totalNoise_fx; /* Q8 */ + Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; /* Q8 */ #endif int16_t totalNoise_increase_len; @@ -2553,8 +2586,11 @@ typedef struct enc_core_structure TEC_ENC_HANDLE hTECEnc; /* TEC encoder handle */ int16_t tec_flag; int16_t tfa_flag; +#ifndef IVAS_FLOAT_FIXED float tfa_enr_flt[N_TEC_TFA_SUBFR]; +#else Word32 tfa_enr[N_TEC_TFA_SUBFR]; +#endif /*---------------------------------------------------------------* * IVAS parameters diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c index 82302f1cf..8a9cf6cd1 100644 --- a/lib_enc/swb_bwe_enc.c +++ b/lib_enc/swb_bwe_enc.c @@ -44,6 +44,9 @@ #include "basop_util.h" #include "basop_proto_func.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -1852,7 +1855,11 @@ void fd_bwe_enc_init( { set_f( hBWE_FD->new_input_hp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ) ); set_f( hBWE_FD->old_input, 0, NS2SA( 48000, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) ); +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_FD->old_input_wb, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); +#else + set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ) ); +#endif set_f( hBWE_FD->old_input_lp, 0, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ) ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float to fix conversions @@ -1864,10 +1871,19 @@ void fd_bwe_enc_init( hBWE_FD->prev_mode = NORMAL; set_f( hBWE_FD->old_wtda_swb, 0, L_FRAME48k ); hBWE_FD->prev_L_swb_norm1 = 8; +#ifndef IVAS_FLOAT_FIXED hBWE_FD->prev_global_gain = 0.0f; +#else + hBWE_FD->prev_global_gain_fx = 0; +#endif hBWE_FD->modeCount = 0; +#ifndef IVAS_FLOAT_FIXED hBWE_FD->EnergyLF = 0.0f; hBWE_FD->mem_old_wtda_swb = 0.0f; +#else + hBWE_FD->EnergyLF_fx = 0; + hBWE_FD->mem_old_wtda_swb_fx = 0; +#endif set_f( hBWE_FD->old_fdbwe_speech, 0.0f, L_FRAME48k ); hBWE_FD->mem_deemph_old_syn = 0.0f; diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index 30f627c40..de6cafa55 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -50,6 +50,7 @@ #include "prot_fx_enc.h" #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants * @@ -265,6 +266,7 @@ void wb_pre_proc( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 3db7b0439..37c799639 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -97,15 +97,31 @@ void InitSWBencBuffer( hBWE_TD->bwe_seed[0] = 23; hBWE_TD->bwe_seed[1] = 59; set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); +#ifndef IVAS_FLOAT_FIXED hBWE_TD->bwe_non_lin_prev_scale = 0; +#else + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->elliptic_bpf_2_48k_mem[0], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[1], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; +#else + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); + set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + hBWE_TD->prev_fb_energy_fx = 0; + move16(); + hBWE_TD->prev_fb_energy_fx_Q = 0; + move16(); +#endif set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); @@ -226,11 +242,15 @@ void InitSWBencBufferStates( set_f( hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k ); #ifndef IVAS_FLOAT_FIXED hBWE_TD->old_mean_EnvSHBres = 0.0f; + hBWE_TD->prev_enr_EnvSHBres = 1.0f; + hBWE_TD->prev_shb_env_tilt = 0.0f; #else hBWE_TD->old_mean_EnvSHBres_fx = 0; + hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ + hBWE_TD->prev_enr_EnvSHBres_e = 31; + hBWE_TD->prev_shb_env_tilt_fx = 0; + hBWE_TD->prev_shb_env_tilt_q = 15; #endif - hBWE_TD->prev_enr_EnvSHBres = 1.0f; - hBWE_TD->prev_shb_env_tilt = 0.0f; hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; #ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_mix_factor = 1.0f; @@ -263,8 +283,13 @@ void ResetSHBbuffer_Enc( hBWE_TD->fb_tbe_demph = 0; /* states for the filters used in generating WB signal from WB excitation*/ +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#else + set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); @@ -2740,7 +2765,6 @@ static void return_M_Least( return; } -#endif /*-------------------------------------------------------------------* * fb_tbe_reset_enc() @@ -2761,7 +2785,6 @@ void fb_tbe_reset_enc( return; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * fb_tbe_enc() * @@ -2934,7 +2957,11 @@ void TBEreset_enc( if ( last_core != ACELP_CORE ) { set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 ); +#ifndef IVAS_FLOAT_FIXED hBWE_TD->bwe_non_lin_prev_scale = 0.f; +#else + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; +#endif } if ( bwidth == WB ) @@ -2957,7 +2984,11 @@ void TBEreset_enc( { set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; +#ifdef IVAS_FLOAT_FIXED + fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); +#else fb_tbe_reset_enc( hBWE_TD->elliptic_bpf_2_48k_mem, &hBWE_TD->prev_fb_energy ); +#endif } } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 7226719ed..f75e6050f 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -7344,6 +7344,7 @@ void InitSWBencBufferStates_fx( hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ hBWE_TD->prev_enr_EnvSHBres_e = 31; hBWE_TD->prev_shb_env_tilt_fx = 0; + hBWE_TD->prev_shb_env_tilt_q = 15; hBWE_TD->prev_pow_exc16kWhtnd_fx = 32767; /*1.0f in Q15*/ hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ hBWE_TD->prev_Env_error_fx = 0; diff --git a/lib_enc/tcx_ltp_enc.c b/lib_enc/tcx_ltp_enc.c index a37e3208d..90c90fae8 100644 --- a/lib_enc/tcx_ltp_enc.c +++ b/lib_enc/tcx_ltp_enc.c @@ -43,6 +43,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * interpolate_corr() * @@ -588,3 +589,4 @@ void tcx_ltp_encode( return; } +#endif diff --git a/lib_enc/transient_detection.c b/lib_enc/transient_detection.c index eeeadfb1a..fc757ed49 100644 --- a/lib_enc/transient_detection.c +++ b/lib_enc/transient_detection.c @@ -66,11 +66,13 @@ static void InitDelayBuffer( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer ); static void InitSubblockEnergies( const int16_t nFrameLength, const int16_t nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitTransientDetector( SubblockEnergies *pSubblockEnergies, const int16_t nDelay, const int16_t nSubblocksToCheck, TCheckSubblocksForAttack pCheckSubblocksForAttack, const float attackRatioThreshold, TransientDetector *pTransientDetector ); +#ifndef IVAS_FLOAT_FIXED static void UpdateDelayBuffer( const float *inputconst, const int16_t nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter( const float *input, const int16_t length, float *pFirState1, float *pFirState2, float *output ); static void UpdateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void CalculateSubblockEnergies( const float *input, const int16_t nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void RunTransientDetector( TransientDetector *pTransientDetector ); +#endif static void GetAttackForTCXDecision( const float *pSubblockNrg, const float *pAccSubblockNrg, const int16_t nSubblocks, const int16_t nPastSubblocks, const float attackRatioThreshold, int16_t *pbIsAttackPresent, int16_t *pAttackIndex ); /*-------------------------------------------------------------------* @@ -208,6 +210,7 @@ float GetTCXMaxenergyChange( } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------* * RunTransientDetection() * @@ -400,6 +403,7 @@ void SetTCXModeInfo( return; } +#endif /*---------------------------------------------------------------* @@ -570,6 +574,7 @@ static void InitTransientDetector( } +#ifndef IVAS_FLOAT_FIXED /* This function should be inlined and WMOPS instrumentation takes that into account, meaning that all references are considered as local variables */ static float InlineFilter( float inValue, @@ -761,6 +766,7 @@ static void CalculateSubblockEnergies( return; } +#endif /*-------------------------------------------------------------------* -- GitLab