From f010b706c876ce80ccc92b306d4aea0f97c87397 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 28 Jan 2026 14:11:06 +0100 Subject: [PATCH 01/22] Unifies IGF_calc and IGFCommonFuncsMDCTSquareSpec EVS and IVAS functions. --- lib_com/igf_base_fx.c | 20 ++++++++++++- lib_com/options.h | 1 + lib_com/prot_fx.h | 7 +++++ lib_dec/igf_dec_fx.c | 66 ++++++++++++++++++++++++++++++++++++++++++- lib_enc/igf_enc_fx.c | 10 +++++++ 5 files changed, 102 insertions(+), 2 deletions(-) diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 79e1ee704..b9498b51f 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1148,7 +1148,12 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 indexOffset, /**< in: Q0 | index offset */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else Word16 indexOffset /**< in: Q0 | index offset */ +#endif ) { Word16 i; @@ -1170,12 +1175,24 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF(EQ_16(element_mode, EVS_MONO)) + { + tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ + } + ELSE + { + tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ + } +#else tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ - mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ +#endif + mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ move32(); } } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* calculate the MDCT square spectrum in the IGF range (for IVAS) **************************************************************************/ @@ -1212,6 +1229,7 @@ void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in move32(); } } +#endif /**********************************************************************/ /* diff --git a/lib_com/options.h b/lib_com/options.h index 6f0d8e55e..2a836e059 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -92,6 +92,7 @@ #define HARM_FD_BWE /* VA: harmonize core-coder FD BWE function duplications */ #define FIX_2411_Harmonize_TNSANALYSIS_DETECTTNSFILT /* FhG: basop issue 2411: harmonize TNSAnalysis*_fx(), DetectTnsFilt*_fx()*/ #define HARMONIZE_READ_DECODE_TNS /* FhG basop 2389: Harm between two pairs of functions. */ +#define FIX_2346_DUPLICATED_IGF_FUNCTIONS /* FhG: basop issue 2346: Review potentially duplicated IGF functions */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 49e042e2d..2520b5e59 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5426,9 +5426,15 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 mdctSpec_e, /**< in: | exponent of mdctSpectrum */ Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 indexOffset, /**< in: Q0 | index offset */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else Word16 indexOffset /**< in: Q0 | index offset */ +#endif ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFCommonFuncsMDCTSquareSpec_ivas( const Word16 sqrtBgn, /**< in: Q0 | start MDCT subband index */ const Word16 sqrtEnd, /**< in: Q0 | stop MDCT subband index */ @@ -5438,6 +5444,7 @@ void IGFCommonFuncsMDCTSquareSpec_ivas( Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ Word16 indexOffset /**< in: Q0 | index offset */ ); +#endif Word16 IGFCommonFuncsIGFConfiguration( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index fba40748c..0b08bd66b 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -1269,7 +1269,12 @@ static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in const Word32 *spectrum, /**< in: Q31 | MDCT spectrum */ const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ +#endif ) { H_IGF_GRID hGrid; @@ -1299,7 +1304,12 @@ static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in spectrum_e, squaredSpectra, squaredSpectra_e, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, + element_mode ); +#else 0 ); +#endif /* calculate the energy per SFB of the survied subbands */ IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, @@ -1320,7 +1330,12 @@ static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in igf_spec_e[i], squaredSpectra, &squaredSpectra_e[i], +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, + element_mode ); +#else 0 ); +#endif /* set all squared values to 0, if the core contains survied lines */ IGF_setLinesToZero( hGrid->tile[i], @@ -1339,7 +1354,7 @@ static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* calculates IGF energies (for IVAS) **************************************************************************/ @@ -1417,6 +1432,7 @@ static void IGF_calc_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in igf_pN_e ); } } +#endif /**********************************************************************/ /* apply IGF @@ -1558,7 +1574,12 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in *spectrum_e, energyTmp, &dE_e, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + negate( tmp ), + EVS_MONO ); +#else negate( tmp ) ); +#endif L_tmp = sum_array_norm( energyTmp, 24, &shift ); /* float: dE = (float)sqrt(dE / 24.f); basop: */ @@ -2222,6 +2243,16 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* collect energy below hGrid->startLine: */ tmp = sub( hGrid->startLine, 24 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFCommonFuncsMDCTSquareSpec( tmp, + hGrid->startLine, + spectrum, + *spectrum_e, + energyTmp, + &dE_e, + negate( tmp ), + IVAS_CPE_MDCT ); +#else IGFCommonFuncsMDCTSquareSpec_ivas( tmp, hGrid->startLine, spectrum, @@ -2229,6 +2260,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in energyTmp, &dE_e, negate( tmp ) ); +#endif L_tmp = sum_array_norm( energyTmp, 24, &shift ); /* float: dE = (float)sqrt(dE / 24.f); basop: */ @@ -3359,7 +3391,12 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in spectrum, *spectrum_e, igf_spec, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + igf_spec_e, + EVS_MONO ); +#else igf_spec_e ); +#endif IGF_appl( hPrivateData, igfGridIdx, spectrum, @@ -3531,12 +3568,22 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in hPrivateData->pSpecFlat_exp, specMed_e, element_mode ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_calc( hPrivateData, + igfGridIdx, + spectrum, + *spectrum_e, + igf_spec, + igf_spec_e, + element_mode ); +#else IGF_calc_ivas( hPrivateData, igfGridIdx, spectrum, *spectrum_e, igf_spec, igf_spec_e ); +#endif IGF_appl_ivas( hPrivateData, igfGridIdx, spectrum, @@ -3806,6 +3853,22 @@ void IGFDecApplyStereo( igf_specR_e_arr, igf_specR_e ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_calc( hPrivateDataL, + igfGridIdx, + spectrumL_fx, + *spectrumL_e, + igf_specL_fx, + igf_specL_e, + IVAS_CPE_MDCT ); + IGF_calc( hPrivateDataR, + igfGridIdx, + spectrumR_fx, + *spectrumR_e, + igf_specR_fx, + igf_specR_e, + IVAS_CPE_MDCT ); +#else IGF_calc_ivas( hPrivateDataL, igfGridIdx, spectrumL_fx, @@ -3818,6 +3881,7 @@ void IGFDecApplyStereo( *spectrumR_e, igf_specR_fx, igf_specR_e ); +#endif IGF_appl_ivas( hPrivateDataL, igfGridIdx, spectrumL_fx, diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 72a26b248..426519a0c 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -156,7 +156,12 @@ static void IGF_CalculateEnvelope( MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, + EVS_MONO ); +#else 0 ); +#endif IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, @@ -173,7 +178,12 @@ static void IGF_CalculateEnvelope( MDCTSpectrum_e, LFMDCTSpectrum, &LFMDCTSpectrum_exp, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, + EVS_MONO ); +#else 0 ); +#endif IGFCommonFuncsCalcSfbEnergyPowerSpec( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, -- GitLab From b467e3ff401a8fb10635e23b61283c2f5fc71e4e Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 29 Jan 2026 14:07:34 +0100 Subject: [PATCH 02/22] Unifies IGF_prep function. --- lib_dec/igf_dec_fx.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 0b08bd66b..22c4d9928 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -525,6 +525,7 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, } } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* prepare IGF spectrum **************************************************************************/ @@ -677,6 +678,23 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } } +#endif + +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +/**********************************************************************/ /* +prepare IGF spectrum +**************************************************************************/ +static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ + Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ + Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ + Word32 *src_spec, /**< in/out: | source spectrum */ + const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ + const Word16 specMed_e, /**< in: | exponent of medium flattening level */ + const Word16 element_mode /**< in: | element mode */ +) +#else /**********************************************************************/ /* prepare IGF spectrum (for IVAS) **************************************************************************/ @@ -690,6 +708,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in const Word16 specMed_e, /**< in: | exponent of medium flattening level */ const Word16 element_mode /**< in: | element mode */ ) +#endif { H_IGF_GRID hGrid; H_IGF_INFO hInfo; @@ -3385,7 +3404,12 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in igf_spec_e, hPrivateData->pSpecFlat, hPrivateData->pSpecFlat_exp, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + specMed_e, + EVS_MONO ); +#else specMed_e ); +#endif IGF_calc( hPrivateData, igfGridIdx, spectrum, @@ -3559,6 +3583,17 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_prep( hPrivateData, + igfGridIdx, + hInstance->infoTCXNoise_ptr, + igf_spec, + igf_spec_e, + hPrivateData->pSpecFlat, + hPrivateData->pSpecFlat_exp, + specMed_e, + element_mode ); +#else IGF_prep_ivas( hPrivateData, igfGridIdx, hInstance->infoTCXNoise_ptr, @@ -3568,6 +3603,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in hPrivateData->pSpecFlat_exp, specMed_e, element_mode ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_calc( hPrivateData, igfGridIdx, -- GitLab From 8b1084d62863d18cf3d4e813ece5d1b6121699f0 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 29 Jan 2026 14:38:53 +0100 Subject: [PATCH 03/22] Unifies IGFDecReadData function. --- lib_com/ivas_prot_fx.h | 3 ++- lib_dec/igf_dec_fx.c | 23 ++++++++++++++++++----- lib_dec/ivas_mdct_core_dec_fx.c | 8 ++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ba65afec0..6f17d9717 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1425,13 +1425,14 @@ void mdct_read_IGF_bits_fx( Decoder_State *st0 /* i : pointer to handle where bitstream is read */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Deccoder */ Decoder_State *st, /* i : decoder state */ const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ const Word16 isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */ ); - +#endif void stereo_tca_init_dec_fx( STEREO_TCA_DEC_HANDLE hStereoTCA /* i/o: Stereo TCA handle for Fixed */ ); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 22c4d9928..baedb2182 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3079,11 +3079,19 @@ static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid han /**********************************************************************/ /* reads whitening information from the bitstream **************************************************************************/ -void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +) +#else +void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) +#endif { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; @@ -3125,7 +3133,11 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in { IGF_decode_whitening_level( st, hPrivateData, 0 ); test(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( ( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) && GT_16( st->element_mode, EVS_MONO ) ) +#else IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) +#endif { tmp = 0; move16(); @@ -3164,6 +3176,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ Decoder_State *st, /**< in: | decoder state */ const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ @@ -3238,7 +3251,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins IGF_decode_temp_flattening_trigger( st, hInstance ); } } - +#endif /**********************************************************************/ /* read the IGF level information from the bitsream **************************************************************************/ diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index c085d5674..518ddf3d4 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -72,7 +72,11 @@ void mdct_read_IGF_bits_fx( /* read IGF payload */ IGFDecReadLevel( st->hIGFDec, st0, temp, 1 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecReadData( st->hIGFDec, st0, temp, 1 ); +#else IGFDecReadData_ivas_fx( st->hIGFDec, st0, temp, 1 ); +#endif } IF( EQ_16( st->core, TCX_10_CORE ) ) @@ -91,7 +95,11 @@ void mdct_read_IGF_bits_fx( } IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); +#else IGFDecReadData_ivas_fx( st->hIGFDec, st0, IGF_GRID_LB_SHORT, temp ); +#endif IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); } -- GitLab From a69342ad090401dc46d376a1261dd81c54d73dbb Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 29 Jan 2026 15:17:14 +0100 Subject: [PATCH 04/22] Removes redundand IGFEncConcatenateBitstream function declarations and renames the function consistently. --- lib_enc/igf_enc_fx.c | 13 +++++++++++++ lib_enc/prot_fx_enc.h | 3 ++- lib_enc/tcx_utils_enc_fx.c | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 426519a0c..e0d6c185b 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1569,6 +1569,18 @@ static void pack_bit_fx( return; } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +/*-------------------------------------------------------------------* + * IGFEncConcatenateBitstream() + * + * IGF bitstream concatenation for TCX10 modes + *-------------------------------------------------------------------*/ + +void IGFEncConcatenateBitstream( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + const Word16 bsBits, /* i : number of IGF bits written to list of indices */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +#else /*-------------------------------------------------------------------* * IGFEncConcatenateBitstream_fx() * @@ -1579,6 +1591,7 @@ void IGFEncConcatenateBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, const Word16 bsBits, /* i : number of IGF bits written to list of indices */ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ) +#endif { Word16 i; IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d6b13aa6e..44b308c5c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2828,6 +2828,7 @@ void IGFEncApplyMono_ivas_fx( const Word16 vad_hover_flag /* i : VAD hangover flag */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFEncConcatenateBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ const Word16 bsBits, /* i : number of IGF bits written to list of indices */ @@ -2841,7 +2842,7 @@ void IGFEncConcatenateBitstream_fx( Word16 *nb_bits, /**< in/out: | total number of bits already written */ Indice *ind_list_fx /**< in: | pointer to list of indices */ ); - +#endif /*isf_msvq_ma.c, lsf_msvq_ma.c*/ void msvq_enc_fx( const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 9765655ba..80bcc5d73 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -3819,7 +3819,11 @@ void ProcessIGF_fx( IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); bsBits = sub( hBstr->nb_ind_tot, pBsStart ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncConcatenateBitstream( hIGFEnc, bsBits, hBstr ); +#else IGFEncConcatenateBitstream_ivas_fx( hIGFEnc, bsBits, hBstr ); +#endif } } @@ -3939,7 +3943,11 @@ void ProcessIGF_ivas_fx( IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); bsBits = sub( hBstr->nb_ind_tot, pBsStart ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncConcatenateBitstream( hIGFEnc, bsBits, hBstr ); +#else IGFEncConcatenateBitstream_ivas_fx( hIGFEnc, bsBits, hBstr ); +#endif } return; @@ -4047,7 +4055,11 @@ void ProcessStereoIGF_fx( IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); bsBits = sub( hBstr->nb_ind_tot, pBsStart ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncConcatenateBitstream( hIGFEnc[ch], bsBits, hBstr ); +#else IGFEncConcatenateBitstream_ivas_fx( hIGFEnc[ch], bsBits, hBstr ); +#endif } } return; -- GitLab From 8fefa17d5af6f59669589853456b1dc4944fe989 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 29 Jan 2026 17:08:28 +0100 Subject: [PATCH 05/22] Unifies IGFDecUpdateInfo function. --- lib_com/prot_fx.h | 11 +++++++++++ lib_dec/dec_tcx_fx.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib_dec/igf_dec_fx.c | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2520b5e59..5d04379c8 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8301,16 +8301,27 @@ void IGFDecSetMode_ivas_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ const Word16 igfGridIdx /**< in: | IGF grid index */ ); +#endif +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +void IGFDecUpdateInfo( + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ + const Word16 subFrameIdx, /* i : index of subframe */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word16 element_mode /* i : IVAS element mode type */ +); +#else void IGFDecUpdateInfo_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ const Word16 subFrameIdx, /* i : subframe index */ const Word16 igfGridIdx /* i : IGF grid index */ ); +#endif void IGFDecCopyLPCFlatSpectrum( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0b954c17c..b82ba4e55 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -219,7 +219,11 @@ void decoder_tcx_fx( test(); IF( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT, st->element_mode ); +#else IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_SHORT ); +#endif } ELSE { @@ -227,11 +231,19 @@ void decoder_tcx_fx( test(); IF( ( EQ_16( st->last_core, ACELP_CORE ) ) || ( left_rect && st->bfi ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN, st->element_mode ); +#else IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_TRAN ); +#endif } ELSE { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM, st->element_mode ); +#else IGFDecUpdateInfo( st->hIGFDec, IGF_GRID_LB_NORM ); +#endif } } @@ -3742,7 +3754,11 @@ void init_tcx_info_fx( test(); IF( EQ_16( *L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_SHORT ); +#endif } ELSE { @@ -3750,11 +3766,19 @@ void init_tcx_info_fx( test(); IF( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN ); +#endif } ELSE { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM ); +#endif } } } @@ -3801,7 +3825,11 @@ void decoder_tcx_IGF_mono_fx( } } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, frame_cnt, igfGridIdx, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, igfGridIdx ); +#endif IF( st->igf ) { @@ -3907,7 +3935,11 @@ void decoder_tcx_IGF_stereo_fx( move16(); } } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( sts[0]->hIGFDec, k, igfGridIdx, sts[0]->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( sts[0]->hIGFDec, k, igfGridIdx ); +#endif test(); IF( EQ_16( L_frame, shr( sts[1]->L_frame, 1 ) ) && ( sts[1]->tcxonly ) ) @@ -3929,7 +3961,11 @@ void decoder_tcx_IGF_stereo_fx( move16(); } } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( sts[1]->hIGFDec, k, igfGridIdx, sts[1]->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( sts[1]->hIGFDec, k, igfGridIdx ); +#endif IF( sts[0]->igf ) @@ -5058,9 +5094,17 @@ void decoder_tcx_noisefilling_fx( { IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x, *x_e, IGF_GRID_LB_SHORT ); /* also replace flat spectrum for the second TCX10 sub frame */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, 1, IGF_GRID_LB_SHORT, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, 1, IGF_GRID_LB_SHORT ); +#endif IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x, *x_e, IGF_GRID_LB_SHORT ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecUpdateInfo( st->hIGFDec, 0, IGF_GRID_LB_SHORT, st->element_mode ); +#else IGFDecUpdateInfo_ivas_fx( st->hIGFDec, 0, IGF_GRID_LB_SHORT ); +#endif Copy( st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB ); } ELSE IF( bfi && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index baedb2182..a882f9024 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4092,6 +4092,7 @@ void IGFDecSetMode_ivas_fx( hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; return; } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ @@ -4117,7 +4118,22 @@ void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in move16(); } } +#endif + +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +/*-------------------------------------------------------------------* + * IGFDecUpdateInfo() + * + * updates the start/stop frequency of IGF according to igfGridIdx + *-------------------------------------------------------------------*/ +void IGFDecUpdateInfo( + const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */ + const Word16 subFrameIdx, /* i : index of subframe */ + const Word16 igfGridIdx, /* i : IGF grid index */ + const Word16 element_mode /* i : IVAS element mode type */ +) +#else /*-------------------------------------------------------------------* * IGFDecUpdateInfo_ivas_fx() * @@ -4129,22 +4145,30 @@ void IGFDecUpdateInfo_ivas_fx( const Word16 subFrameIdx, /* i : index of subframe */ const Word16 igfGridIdx /* i : IGF grid index */ ) +#endif { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) + { +#endif + hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; - hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; - hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; + hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; + hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; - hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; - IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) - { - IGFDecRestoreTCX10SubFrameData_fx( hIGFDec, subFrameIdx ); + IF( EQ_16( igfGridIdx, IGF_GRID_LB_SHORT ) ) + { + IGFDecRestoreTCX10SubFrameData_fx( hIGFDec, subFrameIdx ); + } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } +#endif hPrivateData = &hIGFDec->igfData; IF( hIGFDec->isIGFActive ) -- GitLab From 24c9503753f0e7907cc8c16f398a69a68f8a0732 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 4 Feb 2026 16:56:31 +0100 Subject: [PATCH 06/22] Unifies IGFSCFEncoderEncode_fx function together with static helper functions and removes now obsolete source code file. --- Workspace_msvc/lib_enc.vcxproj | 1 - Workspace_msvc/lib_enc.vcxproj.filters | 3 - lib_com/prot_fx.h | 3 +- lib_enc/igf_enc_fx.c | 8 + lib_enc/igf_scf_enc.c | 327 ------------------------- lib_enc/igf_scf_enc_fx.c | 273 ++++++++++++++++++++- lib_enc/prot_fx_enc.h | 3 + 7 files changed, 283 insertions(+), 335 deletions(-) delete mode 100644 lib_enc/igf_scf_enc.c diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 93a2a8548..110c863c4 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -242,7 +242,6 @@ - diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index 0165869a6..059d48291 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -253,9 +253,6 @@ encoder_all_c - - encoder_all_c - encoder_all_c diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5d04379c8..ffb333d10 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10119,6 +10119,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFSCFEncoderEncode_ivas_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -10127,7 +10128,7 @@ Word16 IGFSCFEncoderEncode_ivas_fx( const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); - +#endif Word16 ari_encode_14bits_ext_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index e0d6c185b..7c7188b24 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -350,7 +350,11 @@ static void IGF_WriteEnvelope( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, EVS_MONO, isIndepFlag ); +#else *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); +#endif move16(); if ( NULL == hBstr ) @@ -3252,7 +3256,11 @@ static Word16 IGF_WriteEnvelope_ivas( IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, IVAS_SCE, isIndepFlag ); +#else *pBitOffset = IGFSCFEncoderEncode_ivas_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, isIndepFlag ); +#endif move16(); if ( NULL == hBstr ) diff --git a/lib_enc/igf_scf_enc.c b/lib_enc/igf_scf_enc.c deleted file mode 100644 index c9a549e5a..000000000 --- a/lib_enc/igf_scf_enc.c +++ /dev/null @@ -1,327 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2026 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.452 Nov 04, 2021. Version 16.4.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot_fx.h" -#include "stat_enc.h" -#include "stat_com.h" -#include "cnst.h" -#include "wmc_auto.h" -#include "prot_fx_enc.h" - - -/*---------------------------------------------------------------------* - * quant_ctx() - * - * - *---------------------------------------------------------------------*/ - -static Word16 quant_ctx( - const Word16 ctx ) -{ - /* - ctx ... -5 -4 -3 -2 -1 0 1 2 3 4 5 ... - Q(ctx)... -3 -3 -3 -2 -1 0 1 2 3 3 3 ... - */ - IF( LE_16( abs_s( ctx ), 3 ) ) - { - return ctx; - } - ELSE IF( GT_16( ctx, 3 ) ) - { - return 3; - } - ELSE /* ctx < -3 */ - { - return -3; - } -} - - -/*---------------------------------------------------------------------* - * arith_encode_bits() - * - * - *---------------------------------------------------------------------*/ - -static void arith_encode_bits( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 x, /* i: value to encode */ - Word16 nBits /* i: number of bits to encode */ -) -{ - Word16 i; - Word16 bit; - - - FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ - { - bit = s_and( shr( x, i ), 1 ); - hPrivateData->ptrBitIndex = ari_encode_14bits_sign_ivas_fx( ptr, - hPrivateData->ptrBitIndex, - 32767, /* disable the bit count limitation */ - &hPrivateData->acState, - bit ); - move16(); - } -} - - -/*---------------------------------------------------------------------* - * arith_encode_residual() - * - * - *---------------------------------------------------------------------*/ - -static void arith_encode_residual( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ - Word16 x, /* i: residual value to encode */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ - Word16 tableOffset /* i: offset used to align the table */ -) -{ - Word16 extra; - Word16 extra_tmp; - Word16 extra_safety; - - - x = add( x, tableOffset ); - - test(); - IF( ( GE_16( x, IGF_MIN_ENC_SEPARATE ) ) && ( LE_16( x, IGF_MAX_ENC_SEPARATE ) ) ) - { - x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ - /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - x, - cumulativeFrequencyTable ); - move16(); - return; - } - - IF( LT_16( x, IGF_MIN_ENC_SEPARATE ) ) - { - /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - 0, - cumulativeFrequencyTable ); - move16(); - } - ELSE /* x > IGF_MAX_ENC_SEPARATE */ - { - /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - IGF_SYMBOLS_IN_TABLE - 1, - cumulativeFrequencyTable ); - move16(); - } - - /* encode one of the tails of the distribution */ - extra_tmp = sub( extra, 15 ); - IF( extra_tmp < 0 ) - { - /* encode extra with 4 bits if extra < 15 */ - arith_encode_bits( hPrivateData, ptr, extra, 4 ); - } - ELSE /* extra >= 15 */ - { - /* send escape code 15 to indicate extra >= 15 */ - arith_encode_bits( hPrivateData, ptr, 15, 4 ); - - extra_safety = sub( extra_tmp, 63 ); - IF( extra_safety < 0 ) - { - /* encode additional extra with 6 bits */ - arith_encode_bits( hPrivateData, ptr, extra_tmp, 6 ); - } - ELSE - { /* extra_tmp >= 63 */ - arith_encode_bits( hPrivateData, ptr, 63, 6 ); - /* encode safety extra with 7 bits */ - arith_encode_bits( hPrivateData, ptr, extra_safety, 7 ); - } - } -} - - -/*---------------------------------------------------------------------* - * encode_sfe_vector() - * - * - *---------------------------------------------------------------------*/ -static void encode_sfe_vector( - IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ - Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ - const Word16 t, /* i : frame counter reset to 0 at each independent frame */ - Word16 *prev_x, /* i : previous vector */ - Word16 *x, /* i : current vector to encode */ - const Word16 length /* i : number of elements to encode */ -) -{ - /* - f - ^ - | d a x - | c b - | e --> t - */ - Word16 f; - Word16 pred; - Word16 ctx; - Word16 ctx_f; - Word16 ctx_t; - - FOR( f = 0; f < length; f++ ) - { - IF( t == 0 ) - { - IF( f == 0 ) - { - /* (t == 0) && (f == 0) */ - /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - shr( x[f], 2 ), - (const UWord16 *) hPrivateData->cf_se00 ); - move16(); - arith_encode_bits( hPrivateData, ptr, x[f] & 3, 2 ); /* LSBs as 2 bit raw */ - } - ELSE IF( EQ_16( f, 1 ) ) - { - pred = x[f - 1]; /* pred = b */ - move16(); - arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); - } - ELSE - { - /* f >= 2 */ - pred = x[f - 1]; /* pred = b */ - move16(); - ctx = quant_ctx( sub( x[f - 1], x[f - 2] ) ); /* Q(b - e) */ - arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), &hPrivateData->cf_se02[( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx )], hPrivateData->cf_off_se02[IGF_CTX_OFFSET + ctx] ); - } - move16(); - } - ELSE - { - /* t == 1 */ - IF( f == 0 ) - { - pred = prev_x[f]; /* pred = a */ - move16(); - arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); - } - ELSE - { - /* (t == 1) && (f >= 1) */ - pred = add( prev_x[f], sub( x[f - 1], prev_x[f - 1] ) ); /* pred = a + b - c */ - ctx_f = quant_ctx( sub( prev_x[f], prev_x[f - 1] ) ); /* Q(a - c) */ - ctx_t = quant_ctx( sub( x[f - 1], prev_x[f - 1] ) ); /* Q(b - c) */ - arith_encode_residual( hPrivateData, ptr, x[f] - pred, &hPrivateData->cf_se11[( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx_f )], hPrivateData->cf_off_se11[IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_CTX_OFFSET + ctx_f )] ); - } - } - } - - return; -} - - -/*---------------------------------------------------------------------* - * IGFSCFEncoderEncode_ivas_fx() - * - * main IGF encoder function - *---------------------------------------------------------------------*/ -Word16 IGFSCFEncoderEncode_ivas_fx( - IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ - Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ - const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ -) -{ - Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each short */ - Word16 i; - - /* insert data: */ - hPublicData->ptrBitIndex = 0; - move16(); - hPublicData->bitCount = bitCount; - move16(); - ari_start_encoding_14bits_ivas_fx( &hPublicData->acState ); /* start AC encoding */ - - /* check if coder needs a reset and do it if necessary */ - IF( indepFlag != 0 ) - { - IGFSCFEncoderReset_fx( hPublicData ); - } - - encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); - - hPublicData->ptrBitIndex = ari_done_encoding_14bits_ivas_fx( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); /* finish AC encoding */ - hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); - move16(); - move16(); - - /* advancing history: */ - Copy( sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] ); - hPublicData->t = add( hPublicData->t, 1 ); - move16(); - - /* copy the bits from the temporary bit buffer, if doRealEncoding is enabled */ - IF( hBstr ) - { - FOR( i = 0; i < hPublicData->ptrBitIndex; ++i ) - { - push_next_indice( hBstr, ptr[i], 1 ); - } - } - - /* return next bit offset in the stream */ - return hPublicData->bitCount; -} diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index d1341a98a..53e86c9b0 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -1,3 +1,37 @@ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +/****************************************************************************************************** + + (C) 2022-2026 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. + +*******************************************************************************************************/ + +#endif /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ @@ -83,7 +117,12 @@ static void arith_encode_bits( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i: value to encode */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 nBits, /* i: number of bits to encode */ + Word16 element_mode /* i: IVAS element mode type */ +#else Word16 nBits /* i: number of bits to encode */ +#endif ) { Word16 i; @@ -93,11 +132,29 @@ static void arith_encode_bits( FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ { bit = s_and( shr( x, i ), 1 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) { + hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx( ptr, + hPrivateData->ptrBitIndex, + 32767, /* disable the bit count limitation */ + &hPrivateData->acState_fx, + bit ); + } + ELSE + { + hPrivateData->ptrBitIndex = ari_encode_14bits_sign_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + 32767, /* disable the bit count limitation */ + &hPrivateData->acState, + bit ); + } +#else hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx( ptr, hPrivateData->ptrBitIndex, 32767, /* disable the bit count limitation */ &hPrivateData->acState_fx, bit ); +#endif move16(); } } @@ -107,7 +164,12 @@ static void arith_encode_residual( Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i: residual value to encode */ const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 tableOffset, /* i: offset used to align the table */ + Word16 element_mode /* i: IVAS element mode type */ +#else Word16 tableOffset /* i: offset used to align the table */ +#endif ) { Word16 extra; @@ -122,11 +184,30 @@ static void arith_encode_residual( { x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF ( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + x, + cumulativeFrequencyTable ); + } + ELSE + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + x, + cumulativeFrequencyTable ); + } +#else hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState_fx, x, cumulativeFrequencyTable ); +#endif move16(); return; } @@ -135,22 +216,60 @@ static void arith_encode_residual( { /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + 0, + cumulativeFrequencyTable ); + } + ELSE + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + 0, + cumulativeFrequencyTable ); + } +#else hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState_fx, 0, cumulativeFrequencyTable ); +#endif move16(); } ELSE /* x > IGF_MAX_ENC_SEPARATE */ { /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + IGF_SYMBOLS_IN_TABLE - 1, + cumulativeFrequencyTable ); + } + ELSE + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + IGF_SYMBOLS_IN_TABLE - 1, + cumulativeFrequencyTable ); + } +#else hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, hPrivateData->ptrBitIndex, &hPrivateData->acState_fx, IGF_SYMBOLS_IN_TABLE - 1, cumulativeFrequencyTable ); +#endif move16(); } @@ -159,28 +278,51 @@ static void arith_encode_residual( IF( extra_tmp < 0 ) { /* encode extra with 4 bits if extra < 15 */ - arith_encode_bits( hPrivateData, ptr, extra, 4 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + arith_encode_bits( hPrivateData, ptr, extra, 4, element_mode ); +#else + arith_encode_bits( hPrivateData, ptr, extra, 4); +#endif } ELSE /* extra >= 15 */ { /* send escape code 15 to indicate extra >= 15 */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + arith_encode_bits( hPrivateData, ptr, 15, 4, element_mode ); +#else arith_encode_bits( hPrivateData, ptr, 15, 4 ); +#endif extra_safety = sub( extra_tmp, 63 ); IF( extra_safety < 0 ) { /* encode additional extra with 6 bits */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + arith_encode_bits( hPrivateData, ptr, extra_tmp, 6, element_mode ); +#else arith_encode_bits( hPrivateData, ptr, extra_tmp, 6 ); +#endif } ELSE { /* extra_tmp >= 63 */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) + { + arith_encode_bits( hPrivateData, ptr, 63, 6, element_mode ); + } +#endif /* encode safety extra with 7 bits */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + arith_encode_bits( hPrivateData, ptr, extra_safety, 7, element_mode ); +#else arith_encode_bits( hPrivateData, ptr, extra_safety, 7 ); +#endif } } } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS static void encode_sfe_vector( IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ @@ -292,7 +434,101 @@ static void encode_sfe_vector( } } } +#else +/*---------------------------------------------------------------------* + * encode_sfe_vector() + * + * + *---------------------------------------------------------------------*/ +static void encode_sfe_vector( + IGFSCFENC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ + Word16 *ptr, /* i : pointer to expanded bit buffer, one bit in each short */ + const Word16 t, /* i : frame counter reset to 0 at each independent frame */ + Word16 *prev_x, /* i : previous vector */ + Word16 *x, /* i : current vector to encode */ + const Word16 length, /* i : number of elements to encode */ + const Word16 element_mode /* i : IVAS element mode type */ +) +{ + /* + f + ^ + | d a x + | c b + | e --> t + */ + Word16 f; + Word16 pred; + Word16 ctx; + Word16 ctx_f; + Word16 ctx_t; + FOR( f = 0; f < length; f++ ) + { + IF( t == 0 ) + { + IF( f == 0 ) + { + /* (t == 0) && (f == 0) */ + /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ + IF ( EQ_16( element_mode, EVS_MONO ) ) + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState_fx, + shr( x[f], 2 ), + (const UWord16 *) hPrivateData->cf_se00 ); + } + ELSE + { + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + shr( x[f], 2 ), + (const UWord16 *) hPrivateData->cf_se00 ); + } + move16(); + arith_encode_bits( hPrivateData, ptr, x[f] & 3, 2, element_mode ); /* LSBs as 2 bit raw */ + } + ELSE IF( EQ_16( f, 1 ) ) + { + pred = x[f - 1]; /* pred = b */ + move16(); + arith_encode_residual( hPrivateData, ptr, x[f] - pred, hPrivateData->cf_se01, hPrivateData->cf_off_se01, element_mode ); + } + ELSE + { + /* f >= 2 */ + pred = x[f - 1]; /* pred = b */ + move16(); + ctx = quant_ctx( sub( x[f - 1], x[f - 2] ) ); /* Q(b - e) */ + arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), &hPrivateData->cf_se02[( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx )], hPrivateData->cf_off_se02[IGF_CTX_OFFSET + ctx], element_mode ); + } + move16(); + } + ELSE + { + /* t == 1 */ + IF( f == 0 ) + { + pred = prev_x[f]; /* pred = a */ + move16(); + arith_encode_residual( hPrivateData, ptr, sub( x[f], pred ), hPrivateData->cf_se10, hPrivateData->cf_off_se10, element_mode ); + } + ELSE + { + /* (t == 1) && (f >= 1) */ + pred = add( prev_x[f], sub( x[f - 1], prev_x[f - 1] ) ); /* pred = a + b - c */ + ctx_f = quant_ctx( sub( prev_x[f], prev_x[f - 1] ) ); /* Q(a - c) */ + ctx_t = quant_ctx( sub( x[f - 1], prev_x[f - 1] ) ); /* Q(b - c) */ + arith_encode_residual( hPrivateData, ptr, x[f] - pred, &hPrivateData->cf_se11[( IGF_SYMBOLS_IN_TABLE + 1 ) * IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_SYMBOLS_IN_TABLE + 1 ) * ( IGF_CTX_OFFSET + ctx_f )], hPrivateData->cf_off_se11[IGF_CTX_COUNT * ( IGF_CTX_OFFSET + ctx_t ) + ( IGF_CTX_OFFSET + ctx_f )], element_mode ); + } + } + } + + return; +} +#endif /**********************************************************************/ /** resets the internal encoder memory (context memory) @@ -318,6 +554,9 @@ Word16 IGFSCFEncoderEncode_fx( const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 element_mode, /* i : IVAS element mode type */ +#endif const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { @@ -330,7 +569,19 @@ Word16 IGFSCFEncoderEncode_fx( move16(); hPublicData->bitCount = bitCount; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /* start AC encoding */ + IF( EQ_16( element_mode, EVS_MONO ) ) + { + ari_start_encoding_14bits_fx( &hPublicData->acState_fx ); + } + ELSE + { + ari_start_encoding_14bits_ivas_fx( &hPublicData->acState ); + } +#else ari_start_encoding_14bits_fx( &hPublicData->acState_fx ); /* start AC encoding */ +#endif /* check if coder needs a reset and do it if necessary */ IF( indepFlag != 0 ) @@ -339,11 +590,27 @@ Word16 IGFSCFEncoderEncode_fx( IGFSCFEncoderReset_fx( hPublicData ); } - encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx], element_mode ); +#else + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); +#endif +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /* finish AC encoding */ + IF( EQ_16( element_mode, EVS_MONO ) ) + { + hPublicData->ptrBitIndex = ari_done_encoding_14bits_fx( ptr, hPublicData->ptrBitIndex, &hPublicData->acState_fx ); + } + ELSE + { + hPublicData->ptrBitIndex = ari_done_encoding_14bits_ivas_fx( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); + } +#else hPublicData->ptrBitIndex = ari_done_encoding_14bits_fx( ptr, hPublicData->ptrBitIndex, - &hPublicData->acState_fx ); /* finish AC encoding */ + &hPublicData->acState_fx ); +#endif hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); move16(); move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 44b308c5c..ee92e1eaa 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3022,6 +3022,9 @@ Word16 IGFSCFEncoderEncode_fx( const Word16 bitCount, /* i : offset to the first bit in bitbuffer which should be readed by iisArithDecoderDecode function */ Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 element_mode, /* i : IVAS element mode type */ +#endif const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); -- GitLab From ad0a9d387b3e9ff574e604c892156c85bd409095 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 11:53:09 +0100 Subject: [PATCH 07/22] Unifies IGF_gridSetUp function. --- lib_com/igf_base_fx.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index b9498b51f..4d77aedf0 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -381,6 +381,7 @@ Word16 IGF_MapBitRateToIndex( return bitRateIndex; /*Q0*/ } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* IGF grid setup **************************************************************************/ @@ -890,6 +891,12 @@ static void IGF_gridSetUp( H_IGF_GRID hGrid, /**< ou } } static void IGF_gridSetUp_ivas_fx( +#else +/**********************************************************************/ /* +IGF grid setup +**************************************************************************/ +static void IGF_gridSetUp( +#endif H_IGF_GRID hGrid, /* o : IGF grid handle */ Word16 bitRateIndex, /* i : IGF bitrate index */ const Word32 sampleRate, /* i : sample rate */ @@ -991,6 +998,10 @@ static void IGF_gridSetUp_ivas_fx( move16(); hGrid->infoGranuleLen = frameLength; /*Q0*/ move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hGrid->infoTransFac = transFac; /*Q14*/ + move16(); +#endif hGrid->sfbWrap[0] = 0; move16(); hGrid->tile[0] = hGrid->startLine; /*Q0*/ @@ -1368,28 +1379,55 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( /* set up regular IGF grid for TCX 20 (transfac = 1.f) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 16384 /*1 Q14*/, + igfMinFq ); +#else IGF_gridSetUp_ivas_fx( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 16384 /*1 Q14*/, igfMinFq ); +#endif /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 20480 /*1.25 Q14*/, + igfMinFq ); +#else IGF_gridSetUp_ivas_fx( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 20480 /*1.25 Q14*/, igfMinFq ); +#endif /* set up IGF grid for TCX 10 (transfac = 0.5) */ hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_gridSetUp( hGrid, + hIGFInfo->bitRateIndex, + sampleRate, + frameLength, + 8192 /*0.50f Q14*/, + igfMinFq ); +#else IGF_gridSetUp_ivas_fx( hGrid, hIGFInfo->bitRateIndex, sampleRate, frameLength, 8192 /*0.50f Q14*/, igfMinFq ); +#endif } return retValue; /*Q0*/ -- GitLab From 1212c381b71fc98ead5b1dd969a06033dff7986f Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 12:25:06 +0100 Subject: [PATCH 08/22] Unifies IGFCommonFuncsIGFConfiguration function. --- lib_com/igf_base_fx.c | 2 ++ lib_com/prot_fx.h | 3 ++- lib_dec/igf_dec_fx.c | 4 ++++ lib_enc/igf_enc_fx.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 4d77aedf0..1d243b8ce 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1327,6 +1327,7 @@ Word16 IGFCommonFuncsIGFConfiguration( return retValue; } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ @@ -1432,6 +1433,7 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( return retValue; /*Q0*/ } +#endif /**********************************************************************/ /* selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ffb333d10..fd6908e4e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5454,6 +5454,7 @@ Word16 IGFCommonFuncsIGFConfiguration( const Word16 rf_mode /* i : flag to signal the RF mode */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ @@ -5461,7 +5462,7 @@ Word16 IGFCommonFuncsIGFConfiguration_ivas_fx( H_IGF_INFO hIGFInfo, /* o : IGF info handle */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); - +#endif Word16 IGFCommonFuncsIGFGetCFTables_fx( const Word32 total_brate, /* i : bitrate in bs e.g. 9600 for 9.6kbs */ const Word16 bwidth, /* i : audio bandwidth */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index a882f9024..24b8e2e1b 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4044,7 +4044,11 @@ void IGFDecSetMode_ivas_fx( hIGFDec->isIGFActive = 0; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) +#else IF( IGFCommonFuncsIGFConfiguration_ivas_fx( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) ) +#endif { IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 7c7188b24..26470dfce 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -4042,7 +4042,11 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->SFM_sb_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->SFM_tb_fx, 0, IGF_MAX_SFB ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) +#else IF( IGFCommonFuncsIGFConfiguration_ivas_fx( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) != 0 ) +#endif { IGFSCFEncoderOpen_fx( &hPrivateData->hIGFSCFArithEnc, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode ); -- GitLab From fa3e8e3b3d380325d4508d6913d078a8aaa95900 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 13:37:53 +0100 Subject: [PATCH 09/22] Unifies IGF_RefineGrid function. --- lib_dec/igf_dec_fx.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 24b8e2e1b..923602c55 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -2982,6 +2982,7 @@ static void IGF_getWhiteSpectralData_ivas( /**********************************************************************/ /* refines the IGF grid **************************************************************************/ +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ ) { @@ -3027,6 +3028,10 @@ static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in } static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ +#else +static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid handle */ + const Word16 element_mode /**< in : | IVAS element mode type */ +#endif ) { Word16 a[IGF_MAX_SFB + 1]; @@ -3049,12 +3054,19 @@ static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid han delta = mac_r( 0x00195000, 29491 /*0.45f Q16*/, shl_sat( delta, 5 ) ); a[tmp] = add( hGrid->swb_offset[sfb], shr( delta, 6 ) ); move16(); - // Rounding off delta values >=t+0.5 to t+1 - IF( GE_16( sub( delta, shl( shr( delta, 6 ), 6 ) ), MID ) ) +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) { - a[tmp] = add( a[tmp], 1 ); - move16(); +#endif + // Rounding off delta values >=t+0.5 to t+1 + IF( GE_16( sub( delta, shl( shr( delta, 6 ), 6 ) ), MID ) ) + { + a[tmp] = add( a[tmp], 1 ); + move16(); + } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS } +#endif IF( s_and( a[tmp], 1 ) != 0 ) { a[tmp] = sub( a[tmp], 1 ); @@ -4009,9 +4021,15 @@ void IGFDecSetMode( test(); IF( ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000 ) ) || ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM], element_mode ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN], element_mode ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT], element_mode ); +#else IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] ); IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] ); IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] ); +#endif } } ELSE @@ -4070,9 +4088,15 @@ void IGFDecSetMode_ivas_fx( IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000_CPE ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM], element_mode ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN], element_mode ); + IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT], element_mode ); +#else IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] ); IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] ); IGF_RefineGrid_ivas_fx( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] ); +#endif } /* IGFDecOutInformation(hIGFDec); */ } -- GitLab From ea01cd7e4a0b5ad1b248c7c05b6c0e81d87cd8fd Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 14:22:13 +0100 Subject: [PATCH 10/22] Unifies IGFEncSetMode_fx function. --- lib_com/prot_fx.h | 3 ++- lib_enc/core_enc_init_fx.c | 4 ++++ lib_enc/igf_enc_fx.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fd6908e4e..02996457e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10301,6 +10301,7 @@ void SetModeIndex_ivas_fx( const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) Q0*/ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFEncSetMode_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const Word32 total_brate, /* i : encoder total bitrate */ @@ -10308,7 +10309,7 @@ void IGFEncSetMode_ivas_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); - +#endif void init_tcx_cfg_ivas_fx( TCX_CONFIG_HANDLE hTcxCfg, const Word32 total_brate, diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 23dcd45b1..7ad4fb506 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -1061,7 +1061,11 @@ void init_coder_ace_plus_ivas_fx( test(); IF( st->igf && st->hIGFEnc != NULL ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncSetMode_fx( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode ); +#else IGFEncSetMode_ivas_fx( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode ); +#endif } ELSE IF( st->hIGFEnc != NULL ) { diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 26470dfce..641c0bd88 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1461,6 +1461,7 @@ Word16 IGFEncWriteBitstream_fx( /**< ou return hInstance->infoTotalBitsPerFrameWritten; } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* sets the IGF mode according to given bitrate **************************************************************************/ @@ -1536,7 +1537,7 @@ void IGFEncSetMode_fx( set32_fx( hIGFEnc->spec_be_igf, 0, N_MAX_TCX - IGF_START_MN ); return; } - +#endif /*-------------------------------------------------------------------* * pack_bit() * @@ -1804,11 +1805,19 @@ ivas_error IGF_Reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#else IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#endif } ELSE IF( igf && reset ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#else IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#endif } ELSE IF( !igf && *hIGFEnc != NULL ) { @@ -3990,7 +3999,11 @@ Word16 IGFEncWriteBitstream_ivas_fx( * sets the IGF mode according to given bitrate *-------------------------------------------------------------------*/ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS +void IGFEncSetMode_fx( +#else void IGFEncSetMode_ivas_fx( +#endif const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */ const Word32 total_brate, /* i : encoder total bitrate */ const Word16 bwidth, /* i : encoder audio bandwidth */ @@ -4007,6 +4020,7 @@ void IGFEncSetMode_ivas_fx( set16_fx( hPrivateData->igfScfQuantized, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->igfCurrWhiteningLevel, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->igfPrevWhiteningLevel, 0, IGF_MAX_TILES ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS set16_fx( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); FOR( i = 0; i < IGF_MAX_TILES; i++ ) { @@ -4015,6 +4029,7 @@ void IGFEncSetMode_ivas_fx( hPrivateData->igfPastSFM_pos = 0; move16(); +#endif FOR( i = 0; i < IGF_BITBUFSIZE / 8; i++ ) { @@ -4025,6 +4040,17 @@ void IGFEncSetMode_ivas_fx( move16(); set32_fx( hPrivateData->prevSFM_FIR, 0, IGF_MAX_TILES ); set16_fx( hPrivateData->prevSFM_IIR, 0, IGF_MAX_TILES ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + /* IVAS specific settings */ + set16_fx( hPrivateData->igfWhiteningHangoverCnt, 0, IGF_MAX_TILES ); + FOR( i = 0; i < IGF_MAX_TILES; i++ ) + { + set16_fx( hPrivateData->igfPastSFM_fx[i], -( ONE_IN_Q13 ), IGF_PAST_SFM_LEN ); + } + + hPrivateData->igfPastSFM_pos = 0; + move16(); +#endif set16_fx( hPrivateData->dampingFactorSmoothing, 2, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFM_FIR_SFB_SB_fx, 0, IGF_MAX_SFB ); set16_fx( hPrivateData->prevSFB_FIR_TB_e, 15, IGF_MAX_SFB ); @@ -4418,11 +4444,19 @@ ivas_error IGF_Reconfig( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hIGFEnc\n" ) ); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#else IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#endif } ELSE IF( igf && reset ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncSetMode_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#else IGFEncSetMode_ivas_fx( *hIGFEnc, brate, bwidth, element_mode, rf_mode ); +#endif } ELSE IF( !igf && *hIGFEnc != NULL ) { -- GitLab From cdf48dd0aec97b04b15bfef688a109218f04bd9f Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 15:27:44 +0100 Subject: [PATCH 11/22] Unifies IGF_WriteEnvelope function. --- lib_enc/igf_enc_fx.c | 100 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 641c0bd88..59b2d7e67 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -295,7 +295,7 @@ static void IGF_CalculateEnvelope( return; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* writes IGF SCF values **************************************************************************/ @@ -363,7 +363,86 @@ static void IGF_WriteEnvelope( } } } +#else +/*-------------------------------------------------------------------* + * IGF_WriteEnvelope() + * + * writes IGF SCF values + *-------------------------------------------------------------------*/ +/*! r: number of bits writen */ +static Word16 IGF_WriteEnvelope( + const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /* i : ptr to bitOffset counter */ + const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag, /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + Word16 *igfAllZero, /* i : returns 1 if all IGF scfs are zero, else 0 */ + const Word16 element_mode /* i : IVAS element mode type */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 sfb; + Word16 totBitCount; + Word16 startBitCount; + + startBitCount = *pBitOffset; + totBitCount = 0; + *igfAllZero = 1; + move16(); + move16(); + move16(); + hPrivateData = &hIGFEnc->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + FOR( sfb = hGrid->startSfb; sfb < hGrid->stopSfb; sfb++ ) + { + IF( hPrivateData->igfScfQuantized[sfb] != 0 ) + { + *igfAllZero = 0; + move16(); + BREAK; + } + } + + IF( *igfAllZero != 0 ) + { + IGF_write_bit_fx( hBstr, pBitOffset, 1 ); + + if ( NULL == hBstr ) + { + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + + IGFSCFEncoderReset_fx( &hPrivateData->hIGFSCFArithEnc ); + + if ( NULL == hBstr ) + { + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + } + ELSE + { + IGF_write_bit_fx( hBstr, pBitOffset, 0 ); + + if ( NULL == hBstr ) + { + IGFSCFEncoderSaveContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + + *pBitOffset = IGFSCFEncoderEncode_fx( &hPrivateData->hIGFSCFArithEnc, hBstr, *pBitOffset, &hPrivateData->igfScfQuantized[hGrid->startSfb], igfGridIdx, element_mode, isIndepFlag ); + move16(); + + if ( NULL == hBstr ) + { + IGFSCFEncoderRestoreContextState_fx( &hPrivateData->hIGFSCFArithEnc, igfGridIdx ); + } + } + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#endif /**********************************************************************/ /* identifies significant spectral content **************************************************************************/ @@ -1442,7 +1521,12 @@ Word16 IGFEncWriteBitstream_fx( /**< ou pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + &igfAllZero, /* o: *igfAllZero */ + EVS_MONO ); /* i: IVAS element mode type */ +#else &igfAllZero ); /* o: *igfAllZero */ +#endif IGF_WriteWhiteningLevels_fx( hInstance, /* i: instance handle of IGF Encoder */ hBstr, /* i: encoder state */ @@ -3199,7 +3283,7 @@ static void IGF_CalculateStereoEnvelope_fx( return; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGF_WriteEnvelope() * @@ -3282,7 +3366,7 @@ static Word16 IGF_WriteEnvelope_ivas( return totBitCount; } - +#endif /*-------------------------------------------------------------------* * IGF_Whitening() * @@ -3967,12 +4051,22 @@ Word16 IGFEncWriteBitstream_ivas_fx( move16(); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_WriteEnvelope( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + &igfAllZero, /* o: *igfAllZero */ + IVAS_SCE ); /* i: IVAS element mode type */ +#else IGF_WriteEnvelope_ivas( hIGFEnc, /* i: instance handle of IGF Encoder */ hBstr, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ &igfAllZero ); /* o: *igfAllZero */ +#endif IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ hBstr, /* i: encoder state */ -- GitLab From e2a26dee18d27ca6fbc8644e5415163feedd6539 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 15:47:41 +0100 Subject: [PATCH 12/22] Unifies IGF_WriteFlatteningTrigger_fx function. --- lib_enc/igf_enc_fx.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 59b2d7e67..b8b8308e8 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1447,6 +1447,7 @@ static void IGF_WriteWhiteningLevels_fx( } } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* write flattening trigger **************************************************************************/ @@ -1464,7 +1465,38 @@ static void IGF_WriteFlatteningTrigger_fx( IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); } +#else +/*-------------------------------------------------------------------* + * IGF_WriteFlatteningTrigger_fx() + * + * write flattening trigger + *-------------------------------------------------------------------*/ + +/*! r: number of bits written */ +static Word16 IGF_WriteFlatteningTrigger_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ + BSTR_ENC_HANDLE hBstr, /**< inout: | encoder bitstream handle */ + Word16 *pBitOffset /**< in: | ptr to bitOffset counter */ +) +{ + Word16 flatteningTrigger; + Word16 totBitCount; + Word16 startBitCount; + totBitCount = 0; + startBitCount = *pBitOffset; + flatteningTrigger = hInstance->flatteningTrigger; + move16(); + move16(); + move16(); + + IGF_write_bits( hBstr, pBitOffset, flatteningTrigger, 1 ); + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} + +#endif /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx **************************************************************************/ @@ -3990,7 +4022,7 @@ static Word16 IGF_WriteWhiteningLevels_ivas_fx( return totBitCount; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGF_WriteFlatteningTrigger_fx() * @@ -4020,7 +4052,7 @@ static Word16 IGF_WriteFlatteningTrigger_ivas_fx( return totBitCount; } - +#endif /*-------------------------------------------------------------------* * IGFEncWriteBitstream() @@ -4074,9 +4106,15 @@ Word16 IGFEncWriteBitstream_ivas_fx( igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_WriteFlatteningTrigger_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset ); /* i: ptr to bitOffset counter */ +#else IGF_WriteFlatteningTrigger_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ hBstr, /* i: encoder state */ pBitOffset ); /* i: ptr to bitOffset counter */ +#endif hIGFEnc->infoTotalBitsPerFrameWritten = sub( *pBitOffset, startBitCount ); hIGFEnc->infoTotalBitsWritten = add( hIGFEnc->infoTotalBitsWritten, hIGFEnc->infoTotalBitsPerFrameWritten ); -- GitLab From 1d7580a26bb4fccdc31686410967a033d4cbd0d5 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 16:07:35 +0100 Subject: [PATCH 13/22] Unifies IGF_WriteWhiteningTile_fx function. --- lib_enc/igf_enc_fx.c | 57 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index b8b8308e8..131ae58bc 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1317,7 +1317,7 @@ static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in return; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* write whitening levels into bitstream **************************************************************************/ @@ -1348,7 +1348,50 @@ static void IGF_WriteWhiteningTile_fx( return; } +#else +/*-------------------------------------------------------------------* + * IGF_WriteWhiteningTile_fx() + * + * write whitening levels into bitstream + *-------------------------------------------------------------------*/ + +/*! r: number of bits written */ +static Word16 IGF_WriteWhiteningTile_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + Word16 whiteningLevel /**< in: Q0 | whitening levels to write */ +) +{ + Word16 totBitCount; + Word16 startBitCount; + + totBitCount = 0; + startBitCount = *pBitOffset; + move16(); + move16(); + + IF( EQ_16( whiteningLevel, IGF_WHITENING_MID ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + ELSE + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + IF( EQ_16( whiteningLevel, IGF_WHITENING_OFF ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + ELSE + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + } + } + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#endif /**********************************************************************/ /* writes the whitening levels **************************************************************************/ @@ -3858,7 +3901,7 @@ static void IGF_Whitening_ivas_fx( return; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGF_WriteWhiteningTile_fx() * @@ -3900,7 +3943,7 @@ static Word16 IGF_WriteWhiteningTile_ivas_fx( return totBitCount; } - +#endif /*-------------------------------------------------------------------* * IGF_WriteWhiteningLevels_fx() @@ -3971,7 +4014,11 @@ static Word16 IGF_WriteWhiteningLevels_ivas_fx( { IGF_write_bits( hBstr, pBitOffset, 0, 1 ); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); +#else IGF_WriteWhiteningTile_ivas_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); +#endif p = 1; move16(); tmp32 = 0; @@ -4008,7 +4055,11 @@ static Word16 IGF_WriteWhiteningLevels_ivas_fx( IGF_write_bits( hBstr, pBitOffset, 1, 1 ); FOR( p = 1; p < nTiles; p++ ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); +#else IGF_WriteWhiteningTile_ivas_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); +#endif } } ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) -- GitLab From 3312ffb17295c42f140f44276241e506548fe4eb Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 16:23:28 +0100 Subject: [PATCH 14/22] Unifies IGFEncWriteConcatenatedBitstream_fx function. --- lib_enc/enc_prm_fx.c | 4 ++++ lib_enc/igf_enc_fx.c | 2 ++ lib_enc/ivas_mdct_core_enc_fx.c | 4 ++++ lib_enc/prot_fx_enc.h | 3 ++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index e28dd0bf9..ef3294e9d 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -1095,7 +1095,11 @@ void writeTCXparam_fx( test(); IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && k == 0 && st->igf && EQ_16( core, TCX_10_CORE ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + nbits_igf = IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); /* Q0 */ +#else nbits_igf = IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr ); /* Q0 */ +#endif } flag_ctx_hm = 0; diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 131ae58bc..06257f22f 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1844,6 +1844,7 @@ Word16 IGFEncWriteConcatenatedBitstream_fx( return hInstance->infoTotalBitsWritten; } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFEncWriteConcatenatedBitstream_ivas_fx( /**< out: Q0 | total number of bits written */ const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ @@ -1872,6 +1873,7 @@ Word16 IGFEncWriteConcatenatedBitstream_ivas_fx( return hInstance->infoTotalBitsWritten; } +#endif /**********************************************************************/ /* apply the IGF encoder, main encoder interface diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index 560cd81bd..c3e762414 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -1100,7 +1100,11 @@ void enc_prm_igf_mdct( } ELSE { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteConcatenatedBitstream_fx( st->hIGFEnc, hBstr ); +#else IGFEncWriteConcatenatedBitstream_ivas_fx( st->hIGFEnc, hBstr ); +#endif } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index ee92e1eaa..a6f4d2ef0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2641,12 +2641,13 @@ Word16 IGFEncWriteConcatenatedBitstream_fx( BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**< out: Q0 | total number of bits written */ Word16 IGFEncWriteConcatenatedBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hInstance, /* i : instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); - +#endif void signaling_enc_rf_fx( Encoder_State *st /* i : encoder state structure */ ); -- GitLab From 0c8ee3c685d3e9532b84e0603c1e0d05619b81bb Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Thu, 5 Feb 2026 16:37:30 +0100 Subject: [PATCH 15/22] Adds clang format check fixes. --- lib_com/igf_base_fx.c | 12 ++++++------ lib_com/prot_fx.h | 2 +- lib_dec/igf_dec_fx.c | 38 +++++++++++++++++++------------------- lib_enc/igf_enc_fx.c | 40 ++++++++++++++++++++-------------------- lib_enc/igf_scf_enc_fx.c | 31 ++++++++++++++++--------------- lib_enc/prot_fx_enc.h | 4 ++-- 6 files changed, 64 insertions(+), 63 deletions(-) diff --git a/lib_com/igf_base_fx.c b/lib_com/igf_base_fx.c index 1d243b8ce..45748b9c9 100644 --- a/lib_com/igf_base_fx.c +++ b/lib_com/igf_base_fx.c @@ -1160,10 +1160,10 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in Word32 *mdctSquareSpec, /**< out: | MDCT square spectrum */ Word16 *mdctSquareSpec_e, /**< out: | exponent of mdctSquareSpec */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 indexOffset, /**< in: Q0 | index offset */ - const Word16 element_mode /**< in: | IVAS element mode type */ + Word16 indexOffset, /**< in: Q0 | index offset */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else - Word16 indexOffset /**< in: Q0 | index offset */ + Word16 indexOffset /**< in: Q0 | index offset */ #endif ) { @@ -1187,18 +1187,18 @@ void IGFCommonFuncsMDCTSquareSpec( const Word16 sqrtBgn, /**< in FOR( i = sqrtBgn; i < sqrtEnd; i++ ) { #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF(EQ_16(element_mode, EVS_MONO)) + IF( EQ_16( element_mode, EVS_MONO ) ) { tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ } ELSE { - tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ + tmp = extract_h( L_shl( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ } #else tmp = round_fx_sat( L_shl_sat( mdctSpec[i], s1 ) ); /*(15 - mdctSpec_e)+ S1*/ #endif - mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ + mdctSquareSpec[j++] = L_mult0( tmp, tmp ); /*31 - mdctSquareSpec_e*/ move32(); } } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 02996457e..22a774e37 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5430,7 +5430,7 @@ void IGFCommonFuncsMDCTSquareSpec( Word16 indexOffset, /**< in: Q0 | index offset */ const Word16 element_mode /**< in: | IVAS element mode type */ #else - Word16 indexOffset /**< in: Q0 | index offset */ + Word16 indexOffset /**< in: Q0 | index offset */ #endif ); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 923602c55..7cf7ecc68 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -684,15 +684,15 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /**********************************************************************/ /* prepare IGF spectrum **************************************************************************/ -static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ - Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ - Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ - Word32 *src_spec, /**< in/out: | source spectrum */ - const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ - const Word16 specMed_e, /**< in: | exponent of medium flattening level */ - const Word16 element_mode /**< in: | element mode */ +static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in: | IGF private data handle */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 *TCXNoise, /**< in: Q0 | TCX noise vector */ + Word32 *igf_spec, /**< in/out: | prepared IGF spectrum */ + Word16 *igf_spec_e, /**< in/out: | array exponents of igf_spec, one exponent per tile */ + Word32 *src_spec, /**< in/out: | source spectrum */ + const Word16 src_spec_e, /**< in: | exponent of src_spec, whitening off */ + const Word16 specMed_e, /**< in: | exponent of medium flattening level */ + const Word16 element_mode /**< in: | element mode */ ) #else /**********************************************************************/ /* @@ -1289,10 +1289,10 @@ static void IGF_calc( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in const Word16 spectrum_e, /**< in: | exponent of pSpectralData */ Word32 *igf_spec, /**< in: Q31 | prepared IGF spectrum */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ - const Word16 element_mode /**< in: | IVAS element mode type */ + Word16 *igf_spec_e, /**< in: | array exponents of igf_spec, one exponent per tile */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else - Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ + Word16 *igf_spec_e /**< in: | array exponents of igf_spec, one exponent per tile */ #endif ) { @@ -2983,7 +2983,7 @@ static void IGF_getWhiteSpectralData_ivas( refines the IGF grid **************************************************************************/ #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ +static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ ) { Word16 a[IGF_MAX_SFB + 1]; @@ -3029,8 +3029,8 @@ static void IGF_RefineGrid( H_IGF_GRID hGrid /**< in static void IGF_RefineGrid_ivas_fx( H_IGF_GRID hGrid /**< in/out: | IGF grid handle */ #else -static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid handle */ - const Word16 element_mode /**< in : | IVAS element mode type */ +static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid handle */ + const Word16 element_mode /**< in : | IVAS element mode type */ #endif ) { @@ -3092,10 +3092,10 @@ static void IGF_RefineGrid( H_IGF_GRID hGrid, /**< in/out: | IGF grid ha reads whitening information from the bitstream **************************************************************************/ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ - Decoder_State *st, /**< in: | decoder state */ - const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ +void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ + Decoder_State *st, /**< in: | decoder state */ + const Word16 igfGridIdx, /**< in: Q0 | in case of CELP->TCX switching, use 1.25 framelength */ + const Word16 isIndepFrame /**< in: Q0 | if 1: arith dec force reset, if 0: no reset */ ) #else void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Deccoder */ diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 06257f22f..0e57019d6 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1591,14 +1591,14 @@ Word16 IGFEncWriteBitstream_fx( /**< ou move16(); } - IGF_WriteEnvelope( hInstance, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + IGF_WriteEnvelope( hInstance, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - &igfAllZero, /* o: *igfAllZero */ - EVS_MONO ); /* i: IVAS element mode type */ + &igfAllZero, /* o: *igfAllZero */ + EVS_MONO ); /* i: IVAS element mode type */ #else &igfAllZero ); /* o: *igfAllZero */ #endif @@ -4137,20 +4137,20 @@ Word16 IGFEncWriteBitstream_ivas_fx( } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IGF_WriteEnvelope( hIGFEnc, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ - &igfAllZero, /* o: *igfAllZero */ - IVAS_SCE ); /* i: IVAS element mode type */ + IGF_WriteEnvelope( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + &igfAllZero, /* o: *igfAllZero */ + IVAS_SCE ); /* i: IVAS element mode type */ #else - IGF_WriteEnvelope_ivas( hIGFEnc, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ - &igfAllZero ); /* o: *igfAllZero */ + IGF_WriteEnvelope_ivas( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + &igfAllZero ); /* o: *igfAllZero */ #endif IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index 53e86c9b0..5b9d8d71d 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -118,10 +118,10 @@ static void arith_encode_bits( Word16 *ptr, /* i/o: pointer to expanded bit buffer, one bit in each Word16 */ Word16 x, /* i: value to encode */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 nBits, /* i: number of bits to encode */ - Word16 element_mode /* i: IVAS element mode type */ + Word16 nBits, /* i: number of bits to encode */ + Word16 element_mode /* i: IVAS element mode type */ #else - Word16 nBits /* i: number of bits to encode */ + Word16 nBits /* i: number of bits to encode */ #endif ) { @@ -133,7 +133,8 @@ static void arith_encode_bits( { bit = s_and( shr( x, i ), 1 ); #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( EQ_16( element_mode, EVS_MONO ) ) { + IF( EQ_16( element_mode, EVS_MONO ) ) + { hPrivateData->ptrBitIndex = ari_encode_14bits_sign_fx( ptr, hPrivateData->ptrBitIndex, 32767, /* disable the bit count limitation */ @@ -165,10 +166,10 @@ static void arith_encode_residual( Word16 x, /* i: residual value to encode */ const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - Word16 tableOffset, /* i: offset used to align the table */ - Word16 element_mode /* i: IVAS element mode type */ + Word16 tableOffset, /* i: offset used to align the table */ + Word16 element_mode /* i: IVAS element mode type */ #else - Word16 tableOffset /* i: offset used to align the table */ + Word16 tableOffset /* i: offset used to align the table */ #endif ) { @@ -183,9 +184,9 @@ static void arith_encode_residual( IF( ( GE_16( x, IGF_MIN_ENC_SEPARATE ) ) && ( LE_16( x, IGF_MAX_ENC_SEPARATE ) ) ) { x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ - /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ + /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF ( EQ_16( element_mode, EVS_MONO ) ) + IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, hPrivateData->ptrBitIndex, @@ -281,7 +282,7 @@ static void arith_encode_residual( #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS arith_encode_bits( hPrivateData, ptr, extra, 4, element_mode ); #else - arith_encode_bits( hPrivateData, ptr, extra, 4); + arith_encode_bits( hPrivateData, ptr, extra, 4 ); #endif } ELSE /* extra >= 15 */ @@ -471,7 +472,7 @@ static void encode_sfe_vector( { /* (t == 0) && (f == 0) */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - IF ( EQ_16( element_mode, EVS_MONO ) ) + IF( EQ_16( element_mode, EVS_MONO ) ) { hPrivateData->ptrBitIndex = ari_encode_14bits_ext_fx( ptr, hPrivateData->ptrBitIndex, @@ -555,9 +556,9 @@ Word16 IGFSCFEncoderEncode_fx( Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 element_mode, /* i : IVAS element mode type */ #endif - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ) { Word16 ptr[IGF_BITBUFSIZE]; /* temporary expanded bit buffer, one bit in each Word16 */ @@ -591,9 +592,9 @@ Word16 IGFSCFEncoderEncode_fx( } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx], element_mode ); + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx], element_mode ); #else - encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); + encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); #endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index a6f4d2ef0..bdd5ae5f4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3024,9 +3024,9 @@ Word16 IGFSCFEncoderEncode_fx( Word16 *sfe, /* i : ptr to an array which contain quantized scalefactor energies */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 element_mode, /* i : IVAS element mode type */ + const Word16 element_mode, /* i : IVAS element mode type */ #endif - const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); void IGFSCFEncoderSaveContextState_fx( -- GitLab From 7a3cf372bad9f18c199ef9ca9fac03816f3ac4d4 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Tue, 10 Feb 2026 11:23:26 +0100 Subject: [PATCH 16/22] Unifies IGF_WriteWhiteningLevels_fx function. --- lib_enc/igf_enc_fx.c | 134 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 2 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 0e57019d6..c5d8a8e1e 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1392,6 +1392,7 @@ static Word16 IGF_WriteWhiteningTile_fx( } #endif +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* writes the whitening levels **************************************************************************/ @@ -1489,7 +1490,128 @@ static void IGF_WriteWhiteningLevels_fx( } } } +#else +/*-------------------------------------------------------------------* + * IGF_WriteWhiteningLevels_fx() + * + * writes the whitening levels + *-------------------------------------------------------------------*/ + +/**< out: Q0 | total number of bits written */ +static Word16 IGF_WriteWhiteningLevels_fx( + const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF encoder */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ + const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +) +{ + IGF_ENC_PRIVATE_DATA_HANDLE hPrivateData; + H_IGF_GRID hGrid; + Word16 p; + Word16 nTiles; + Word16 isSame; + Word32 tmp32; + Word16 totBitCount; + Word16 startBitCount; + + totBitCount = 0; + move16(); + isSame = 1; + move16(); + startBitCount = *pBitOffset; + move16(); + hPrivateData = &hInstance->igfData; + hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; + nTiles = hGrid->nTiles; + move16(); + + IF( isIndepFlag ) + { + isSame = 0; + move16(); + } + ELSE + { + p = 0; + move16(); + tmp32 = 0; + move32(); + test(); + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) + { + test(); + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfPrevWhiteningLevel[p] ); + if ( tmp32 != 0 ) + { + isSame = 0; + move16(); + } + p++; + } + } + IF( isSame ) + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + } + ELSE + { + IF( !isIndepFlag ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[0] ); + p = 1; + move16(); + tmp32 = 0; + move32(); + test(); + IF( EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) || EQ_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + isSame = 1; + move16(); + } + ELSE + { + if ( LT_16( p, nTiles ) ) + { + isSame = 1; + move16(); + } + test(); + WHILE( ( LT_16( p, nTiles ) ) && ( tmp32 == 0 ) ) + { + test(); + tmp32 = L_sub( hPrivateData->igfCurrWhiteningLevel[p], hPrivateData->igfCurrWhiteningLevel[p - 1] ); + if ( tmp32 != 0 ) + { + isSame = 0; + move16(); + } + p++; + } + } + test(); + IF( !isSame ) + { + IGF_write_bits( hBstr, pBitOffset, 1, 1 ); + FOR( p = 1; p < nTiles; p++ ) + { + IGF_WriteWhiteningTile_fx( hBstr, pBitOffset, hPrivateData->igfCurrWhiteningLevel[p] ); + } + } + ELSE IF( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000_CPE ) ) + { + IGF_write_bits( hBstr, pBitOffset, 0, 1 ); + } + } + + totBitCount = sub( *pBitOffset, startBitCount ); + + return totBitCount; +} +#endif #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* write flattening trigger @@ -3946,7 +4068,7 @@ static Word16 IGF_WriteWhiteningTile_ivas_fx( return totBitCount; } #endif - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGF_WriteWhiteningLevels_fx() * @@ -4074,7 +4196,7 @@ static Word16 IGF_WriteWhiteningLevels_ivas_fx( return totBitCount; } - +#endif #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGF_WriteFlatteningTrigger_fx() @@ -4153,11 +4275,19 @@ Word16 IGFEncWriteBitstream_ivas_fx( &igfAllZero ); /* o: *igfAllZero */ #endif +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGF_WriteWhiteningLevels_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#else IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ hBstr, /* i: encoder state */ pBitOffset, /* i: ptr to bitOffset counter */ igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_WriteFlatteningTrigger_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ -- GitLab From 2e912710ca8d9e6180eb53acf34b86f30e823911 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Tue, 10 Feb 2026 12:14:23 +0100 Subject: [PATCH 17/22] Unifies IGFEncWriteBitstream_fx function. --- lib_com/prot_fx.h | 3 ++- lib_enc/enc_prm_fx.c | 12 ++++++++++++ lib_enc/igf_enc_fx.c | 11 ++++++++--- lib_enc/ivas_mdct_core_enc_fx.c | 4 ++++ lib_enc/prot_fx_enc.h | 5 +++++ lib_enc/tcx_utils_enc_fx.c | 24 ++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 22a774e37..772bb5a45 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10112,6 +10112,7 @@ void IGFSaveSpectrumForITF_ivas_fx( const Word32 *pITFSpectrum, /* i : MDCT spectrum */ Word16 exp_pITFSpectrum ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFEncWriteBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -10119,7 +10120,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); - +#endif #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGFSCFEncoderEncode_ivas_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index ef3294e9d..2f529a265 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -777,11 +777,19 @@ void enc_prm_fx( move16(); IF( EQ_16( st->last_core, ACELP_CORE ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1, st->element_mode ); +#else IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_TRAN, 1 ); +#endif } ELSE { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1, st->element_mode ); +#else IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, IGF_GRID_LB_NORM, 1 ); +#endif } } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */ @@ -1262,7 +1270,11 @@ void writeTCXparam_fx( } st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, gridIdx, 1, st->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, gridIdx, 1 ); +#endif } total_nbbits = sub( hBstr->nb_bits_tot, nbits_start ); /* Q0 */ diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index c5d8a8e1e..6015976bd 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1695,7 +1695,12 @@ Word16 IGFEncWriteBitstream_fx( /**< ou BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#endif ) { Word16 igfAllZero; @@ -1720,7 +1725,7 @@ Word16 IGFEncWriteBitstream_fx( /**< ou isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS &igfAllZero, /* o: *igfAllZero */ - EVS_MONO ); /* i: IVAS element mode type */ + element_mode ); /* i: IVAS element mode type */ #else &igfAllZero ); /* o: *igfAllZero */ #endif @@ -4228,7 +4233,7 @@ static Word16 IGF_WriteFlatteningTrigger_ivas_fx( return totBitCount; } #endif - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /*-------------------------------------------------------------------* * IGFEncWriteBitstream() * @@ -4306,7 +4311,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( return hIGFEnc->infoTotalBitsPerFrameWritten; } - +#endif /*-------------------------------------------------------------------* * IGFEncSetMode() diff --git a/lib_enc/ivas_mdct_core_enc_fx.c b/lib_enc/ivas_mdct_core_enc_fx.c index c3e762414..96777796c 100644 --- a/lib_enc/ivas_mdct_core_enc_fx.c +++ b/lib_enc/ivas_mdct_core_enc_fx.c @@ -1096,7 +1096,11 @@ void enc_prm_igf_mdct( st->hIGFEnc->infoTotalBitsPerFrameWritten = 0; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1, st->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( st->hIGFEnc, hBstr, &st->hIGFEnc->infoTotalBitsPerFrameWritten, ( st->last_core == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); +#endif } ELSE { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index bdd5ae5f4..1c09bc66d 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2623,7 +2623,12 @@ Word16 IGFEncWriteBitstream_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ +#endif ); void ACcontextMapping_encode2_no_mem_s17_LC_fx( diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 80bcc5d73..2452e96b8 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -3809,14 +3809,22 @@ void ProcessIGF_fx( move16(); IF( isTCX20 ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); +#else IGFEncWriteBitstream_fx( hInstance, NULL, &hInstance->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif } ELSE { pBsStart = hBstr->nb_ind_tot; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif bsBits = sub( hBstr->nb_ind_tot, pBsStart ); #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS @@ -3933,14 +3941,22 @@ void ProcessIGF_ivas_fx( IF( isTCX20 ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hIGFEnc, NULL, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( hIGFEnc, NULL, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif } ELSE { pBsStart = hBstr->nb_ind_tot; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, st->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( hIGFEnc, hBstr, &hIGFEnc->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif bsBits = sub( hBstr->nb_ind_tot, pBsStart ); #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS @@ -4040,7 +4056,11 @@ void ProcessStereoIGF_fx( IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, sts[ch]->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], NULL, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif } ELSE { @@ -4052,7 +4072,11 @@ void ProcessStereoIGF_fx( { hBstr->ind_list = sts[0]->hBstr->ind_list + sts[0]->hBstr->nb_ind_tot; } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFEncWriteBitstream_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag, sts[ch]->element_mode ); +#else IGFEncWriteBitstream_ivas_fx( hIGFEnc[ch], hBstr, &hIGFEnc[ch]->infoTotalBitsPerFrameWritten, igfGridIdx, isIndepFlag ); +#endif bsBits = sub( hBstr->nb_ind_tot, pBsStart ); #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS -- GitLab From 3eb21b44c541abe8a47de8859ef63b964338f11c Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Tue, 10 Feb 2026 16:59:52 +0100 Subject: [PATCH 18/22] Unifies IGF_replaceTCXNoise_1 function. --- lib_dec/igf_dec_fx.c | 169 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 2 deletions(-) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 7cf7ecc68..16e2e176c 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -75,7 +75,7 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou return i; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* measures TCX noise **************************************************************************/ @@ -173,6 +173,82 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q return noise; } +#else + +static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ + const Word32 *in, /**< in: | MDCT spectrum */ + Word16 in_exp, /**< in: | MDCT spectrum exponent */ + Word16 s_l, /**< in: Q0 | noise headroom (for EVS) */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 *totalNoiseNrg, /**< out: | measured noise energy */ + Word16 *totalNoiseNrg_exp, /**< out: | measured noise energy exponent */ + const Word16 element_mode /**< in: | IVAS element mode type */ +) +{ + Word16 sb, tmp16, shift, noise; + Word32 tmp32, nE32; + Word64 nE64; + + shift = 2; + move16(); + noise = 0; + move16(); + tmp16 = 0; + move16(); + tmp32 = 0; + move32(); + nE32 = 0; + move32(); + nE64 = 0; + move64(); + s_l = sub( s_l, 5 ); + + *totalNoiseNrg = 0; + move32(); + IF( totalNoiseNrg_exp ) + { + *totalNoiseNrg_exp = 0; + move16(); + } + + FOR( sb = start; sb < stop; sb++ ) + { + IF( TCXNoise[sb] ) + { + IF( EQ_16( element_mode, EVS_MONO ) ) + { + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l + nE32 = L_mac( nE32, tmp16, tmp16 ); // Q31 + s_l + } + ELSE + { + tmp32 = L_shr( in[sb], shift ); + nE64 = W_mac_32_32( nE64, tmp32, tmp32 ); // 62 - (in_exp + shift + in_exp + shift + 1) + } + noise = add( noise, 1 ); + } + } + + IF( EQ_16( element_mode, EVS_MONO ) ) + { + *totalNoiseNrg = nE32; // Q31 + s_l + move32(); + } + ELSE IF( nE64 ) + { + tmp16 = W_norm( nE64 ); + nE64 = W_shl( nE64, tmp16 ); + *totalNoiseNrg = W_extract_h( nE64 ); + move32(); + *totalNoiseNrg_exp = sub( add( shl( shift, 1 ), shl( in_exp, 1 ) ), tmp16 ); + move16(); + } + + return noise; +} +#endif /**********************************************************************/ /* replaces TCX noise @@ -3388,11 +3464,20 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in igf_spec + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, +#endif hPrivateData->headroom_TCX_noise_white, hInstance->infoTCXNoise_evs, hGrid->minSrcSubband, hGrid->startLine, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + &hPrivateData->totalNoiseNrg, + NULL, + EVS_MONO ); +#else &hPrivateData->totalNoiseNrg ); +#endif move16(); move16(); @@ -3409,11 +3494,20 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in sub( hGrid->startLine, hGrid->minSrcSubband ) ); hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + 0, +#endif hPrivateData->headroom_TCX_noise, hInstance->infoTCXNoise_evs, hGrid->minSrcSubband, hGrid->startLine, +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + &hPrivateData->totalNoiseNrg_off, + NULL, + EVS_MONO ); +#else &hPrivateData->totalNoiseNrg_off ); +#endif move16(); move16(); @@ -3577,6 +3671,17 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in specMed_e = igf_spec_e[i]; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, + igf_spec_e[i], + 0, + hInstance->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg, + &hPrivateData->totalNoiseNrg_exp, + element_mode ); +#else hPrivateData->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_spec, igf_spec_e[i], hInstance->infoTCXNoise_ptr, @@ -3584,6 +3689,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in hGrid->startLine, &hPrivateData->totalNoiseNrg, &hPrivateData->totalNoiseNrg_exp ); +#endif move16(); BREAK; @@ -3596,6 +3702,17 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in IF( EQ_16( hPrivateData->currWhiteningLevel[i], IGF_WHITENING_OFF ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, + hPrivateData->pSpecFlat_exp, + 0, + hInstance->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg_off, + &hPrivateData->totalNoiseNrg_off_exp, + element_mode ); +#else hPrivateData->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateData->pSpecFlat, hPrivateData->pSpecFlat_exp, hInstance->infoTCXNoise_ptr, @@ -3603,6 +3720,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in hGrid->startLine, &hPrivateData->totalNoiseNrg_off, &hPrivateData->totalNoiseNrg_off_exp ); +#endif move16(); BREAK; } @@ -3810,7 +3928,17 @@ void IGFDecApplyStereo( move16(); } - +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL_fx, + specMedL_e, + 0, + hIGFDecL->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataL->totalNoiseNrg, + &hPrivateDataL->totalNoiseNrg_exp, + IVAS_CPE_MDCT ); +#else hPrivateDataL->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specL_fx, specMedL_e, hIGFDecL->infoTCXNoise_ptr, @@ -3818,6 +3946,7 @@ void IGFDecApplyStereo( hGrid->startLine, &hPrivateDataL->totalNoiseNrg, &hPrivateDataL->totalNoiseNrg_exp ); +#endif move16(); IF( !bfi ) @@ -3840,6 +3969,17 @@ void IGFDecApplyStereo( move16(); } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR_fx, + specMedR_e, + 0, + hIGFDecR->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataR->totalNoiseNrg, + &hPrivateDataR->totalNoiseNrg_exp, + IVAS_CPE_MDCT ); +#else hPrivateDataR->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specR_fx, specMedR_e, hIGFDecR->infoTCXNoise_ptr, @@ -3847,6 +3987,7 @@ void IGFDecApplyStereo( hGrid->startLine, &hPrivateDataR->totalNoiseNrg, &hPrivateDataR->totalNoiseNrg_exp ); +#endif move16(); BREAK; } @@ -3857,6 +3998,17 @@ void IGFDecApplyStereo( test(); IF( EQ_16( hPrivateDataL->currWhiteningLevel[i], IGF_WHITENING_OFF ) || EQ_16( hPrivateDataR->currWhiteningLevel[i], IGF_WHITENING_OFF ) ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, + hPrivateDataL->pSpecFlat_exp, + 0, + hIGFDecL->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataL->totalNoiseNrg_off, + &hPrivateDataL->totalNoiseNrg_off_exp, + IVAS_CPE_MDCT ); +#else hPrivateDataL->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataL->pSpecFlat, hPrivateDataL->pSpecFlat_exp, hIGFDecL->infoTCXNoise_ptr, @@ -3864,8 +4016,20 @@ void IGFDecApplyStereo( hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off, &hPrivateDataL->totalNoiseNrg_off_exp ); +#endif move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, + hPrivateDataR->pSpecFlat_exp, + 0, + hIGFDecR->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataR->totalNoiseNrg_off, + &hPrivateDataR->totalNoiseNrg_off_exp, + IVAS_CPE_MDCT ); +#else hPrivateDataR->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataR->pSpecFlat, hPrivateDataR->pSpecFlat_exp, hIGFDecR->infoTCXNoise_ptr, @@ -3873,6 +4037,7 @@ void IGFDecApplyStereo( hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off, &hPrivateDataR->totalNoiseNrg_off_exp ); +#endif move16(); BREAK; } -- GitLab From 8542570a58b8ff68e632ba50736866aeddbeb23e Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Tue, 10 Feb 2026 17:06:50 +0100 Subject: [PATCH 19/22] Unifies IGF_getCrest function. --- lib_enc/igf_enc_fx.c | 47 ++++++++++++++++++++++++++++++++++++++++++- lib_enc/prot_fx_enc.h | 12 ++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 6015976bd..b30141c1a 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -794,9 +794,18 @@ crest factor calculation Word16 IGF_getCrest( /**< out: Q15| crest factor */ Word16 *crest_exp, /**< out: | exponent of crest factor */ const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ +#else const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ +#endif const Word16 start, /**< in: Q0 | start subband index */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 stop /**< in: Q0 | stop subband index */ +#endif ) { Word16 i; @@ -807,6 +816,9 @@ Word16 IGF_getCrest( /**< ou Word16 crest; Word16 tmp; Word32 tmp32; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word16 powSpec_exp; +#endif x_eff32 = 0; move32(); @@ -816,13 +828,25 @@ Word16 IGF_getCrest( /**< ou move16(); *crest_exp = 1; move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + powSpec_exp = powerSpectrum_exp[0]; + move16(); +#endif FOR( i = start; i < stop; i++ ) { /*x = max(0, (int)(log(powerSpectrum[i]) * INV_LOG_2));*/ /*see IGF_getSFM for more comment */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) + { + powSpec_exp = powerSpectrum_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ + } + x = sub( sub( powSpec_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ +#else x = sub( sub( powerSpectrum_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ +#endif if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ { x = 0; @@ -871,7 +895,7 @@ Word16 IGF_getCrest( /**< ou return crest; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS Word16 IGF_getCrest_ivas( /**< out: Q15| crest factor */ Word16 *crest_exp, /**< out: | exponent of crest factor */ const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ @@ -952,6 +976,7 @@ Word16 IGF_getCrest_ivas( /**< out: Q15| crest return crest; } +#endif /************************************************************************* calculates spectral flatness measurment @@ -1230,7 +1255,11 @@ static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in { /*tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/ SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + crest = IGF_getCrest( &crest_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1], EVS_MONO ); +#else crest = IGF_getCrest( &crest_exp, powerSpectrum, powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); +#endif tmp = BASOP_Util_Divide1616_Scale( SFM, crest, &s ); /* Q15 */ s = add( s, sub( SFM_exp, crest_exp ) ); @@ -3134,13 +3163,21 @@ static void IGF_CalculateStereoEnvelope_fx( // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); +#else crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); +#endif tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp); sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); +#else crest = IGF_getCrest_ivas( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); +#endif tmp_sb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); tmp_sb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_sb_fx*/ @@ -3285,7 +3322,11 @@ static void IGF_CalculateStereoEnvelope_fx( Word16 shift = shr( width, 1 ); // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); +#else crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); +#endif shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), threshold_fx, add( threshold_e, 16 ) ), 1 ) && ( NE_16( sfb, sub( hGrid->sfbWrap[hGrid->nTiles], 1 ) ) ) ) @@ -3294,7 +3335,11 @@ static void IGF_CalculateStereoEnvelope_fx( shift = shr( width, 1 ); // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); +#else crest = IGF_getCrest_ivas( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); +#endif shiftedSFM_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &shiftedSFM_e ); } IF( shiftedSFM_fx ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1c09bc66d..2231fe799 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2757,11 +2757,21 @@ void IGF_UpdateInfo( Word16 IGF_getCrest( Word16 *crest_exp, /**< out: | exponent of crest factor */ const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 *powerSpectrum_exp,/**< in: | exponent of power spectrum */ +#else const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ +#endif const Word16 start, /**< in: Q0 | start subband index */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 stop /**< in: Q0 | stop subband index */ +#endif ); +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**< out: Q15| crest factor */ Word16 IGF_getCrest_ivas( Word16 *crest_exp, /**< out: | exponent of crest factor */ @@ -2770,7 +2780,7 @@ Word16 IGF_getCrest_ivas( const Word16 start, /**< in: Q0 | start subband index */ const Word16 stop /**< in: Q0 | stop subband index */ ); - +#endif /**< out: Q15| SFM value */ Word16 IGF_getSFM( Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ -- GitLab From 62b81d641e28c8c29f4863ca74dd4939192324d9 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 11 Feb 2026 11:26:07 +0100 Subject: [PATCH 20/22] Unifies IGFDecSetMode function. --- lib_com/prot_fx.h | 4 ++-- lib_dec/core_dec_switch_fx.c | 4 ++++ lib_dec/igf_dec_fx.c | 18 +++++++++++++++++- lib_dec/ivas_mct_dec_fx.c | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 772bb5a45..537cae71a 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8291,7 +8291,7 @@ void IGFDecSetMode( const Word16 defaultStopLine, /* i : default stop subband index */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecSetMode_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ const Word32 total_brate, /* i : bitrate */ @@ -8301,7 +8301,7 @@ void IGFDecSetMode_ivas_fx( const Word16 defaultStopLine, /* i : default stop subband index */ const Word16 rf_mode /* i : flag to signal the RF mode */ ); - +#endif #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecUpdateInfo( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | instance handle of IGF Decoder */ diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 5c824532e..d643ac0c4 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -313,7 +313,11 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->igf && ( ( st->idchan == 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); +#else IGFDecSetMode_ivas_fx( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); +#endif } test(); test(); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 16e2e176c..4b6af5b14 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4184,7 +4184,13 @@ void IGFDecSetMode( move16(); test(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) && EQ_16( element_mode, EVS_MONO ) ) || + ( NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_96000_CPE ) && + NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000 ) && NE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_128000_CPE ) && GT_16( element_mode, EVS_MONO ) ) ) +#else IF( ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_SWB_48000 ) ) || ( LE_16( hPrivateData->igfInfo.bitRateIndex, IGF_BITRATE_FB_48000 ) ) ) +#endif { #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM], element_mode ); @@ -4209,8 +4215,17 @@ void IGFDecSetMode( move16(); fprintf( stderr, "IGFDecSetMode: initialization error!\n" ); } + IF( GT_16( element_mode, EVS_MONO ) ) + { + hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; + hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; + hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + } + return; } - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS void IGFDecSetMode_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */ const Word32 total_brate, /* i : bitrate */ @@ -4285,6 +4300,7 @@ void IGFDecSetMode_ivas_fx( hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; return; } +#endif #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**********************************************************************/ /* updates the start/stop frequency of IGF according to igfGridIdx diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index dd889e83b..0cf2b1c3a 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -676,7 +676,11 @@ ivas_error mct_dec_reconfigure_fx( IF( st->igf ) { +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IGFDecSetMode( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); +#else IGFDecSetMode_ivas_fx( st->hIGFDec, st_ivas->hCPE[cpe_id]->element_brate, st->bwidth, st->element_mode, -1, -1, st->rf_flag ); +#endif } } } -- GitLab From a8d4bc0a2ca3199bfc4e82dac2e3e0340551a1bf Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 11 Feb 2026 14:39:44 +0100 Subject: [PATCH 21/22] Unifies IGF_getSFM function. --- lib_enc/igf_enc_fx.c | 88 ++++++++++++++++++++++++++++++++++++++++++- lib_enc/prot_fx_enc.h | 8 +++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index b30141c1a..121fd4868 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -986,7 +986,12 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value const Word32 *energy, /**< in: Q31| energies */ const Word16 *energy_exp, /**< in: | exponent of energies */ const Word16 start, /**< in: Q0 | start subband index */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 stop /**< in: Q0 | stop subband index */ +#endif ) { Word16 n, i, s; @@ -997,12 +1002,42 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value Word16 numf; Word32 SFM32; Word16 invDenom, SFM; +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + Word64 W_denom; + Word16 en_exp; + +#else move32(); move32(); move32(); +#endif num = 0; move32(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + *SFM_exp = 0; + move16(); + SFM = 32767 /*1.0f Q15*/; + move16(); + en_exp = energy_exp[0]; + move16(); + IF( EQ_16( element_mode, EVS_MONO ) ) + { + denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( en_exp, 31 ) ); + denom = L_max( denom, 1 ); + move32(); + move32(); + W_denom = W_deposit32_l( denom ); + move64(); + } + ELSE + { + denom = 65536; // 1.f in Q16 + move32(); + denom_exp = 15; + move16(); + } +#else denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( *energy_exp, 31 ) ); denom = L_max( denom, 1 ); *SFM_exp = 0; @@ -1011,6 +1046,7 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value move16(); Word64 W_denom = W_deposit32_l( denom ); +#endif FOR( i = start; i < stop; i++ ) { /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/ @@ -1018,8 +1054,14 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value /* n = sub(sub(31,norm_l(tmp32)),1); */ /*<- ld */ /* n = sub(n,31); */ /*<- -Qx */ /* n = add(n,*energy_exp); */ /*<- +xExp */ - +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( GT_16( element_mode, EVS_MONO ) ) { + en_exp = energy_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ + } + n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ +#else n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ +#endif if ( energy[i] == 0 ) /*special case: energy is zero*/ { @@ -1030,11 +1072,28 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value n = s_max( 0, n ); num = L_add( num, L_deposit_l( n ) ); /*Q0*/ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) { + W_denom = W_add( W_deposit32_l( energy[i] ), W_denom ); + } + ELSE + { + denom = BASOP_Util_Add_Mant32Exp( energy[i], en_exp, denom, denom_exp, &denom_exp ); + } +#else W_denom = W_add( W_deposit32_l( energy[i] ), W_denom ); +#endif } +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + IF( EQ_16( element_mode, EVS_MONO ) ) { + denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ + denom_exp = add( denom_exp, en_exp ); + } +#else denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ denom_exp = add( denom_exp, *energy_exp ); +#endif /* calculate SFM only if signal is present */ IF( denom != 0 ) @@ -1082,6 +1141,7 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value return SFM /*Q15*/; } +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /************************************************************************* calculates spectral flatness measurment **************************************************************************/ @@ -1178,7 +1238,7 @@ Word16 IGF_getSFM_ivas_fx( /**< out: Q15| SFM value return SFM /*Q15*/; } - +#endif /**********************************************************************/ /* calculates the IGF whitening levels by SFM and crest **************************************************************************/ @@ -1254,7 +1314,11 @@ static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< in FOR( p = 0; p < nT; p++ ) { /*tmp = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1], EVS_MONO ); +#else SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS crest = IGF_getCrest( &crest_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1], EVS_MONO ); #else @@ -3161,8 +3225,13 @@ static void IGF_CalculateStereoEnvelope_fx( move16(); move16(); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + // tmp_tb = IGF_getSFM(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); +#else // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT ); #else @@ -3171,8 +3240,13 @@ static void IGF_CalculateStereoEnvelope_fx( tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e ); tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + // tmp_sb = IGF_getSFM(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest(tileSrcSpec, 0, strt_cpy - tmp); + sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); +#else // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp); sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT ); #else @@ -3320,8 +3394,13 @@ static void IGF_CalculateStereoEnvelope_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), negate( threshold_fx ), add( threshold_e, 16 ) ), -1 ) ) { Word16 shift = shr( width, 1 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); +#else // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); #else @@ -3333,8 +3412,13 @@ static void IGF_CalculateStereoEnvelope_fx( { Word16 shift; shift = shr( width, 1 ); +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); + sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); +#else // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ); sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) ); +#endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT ); #else diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2231fe799..44b6f2b2f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2787,9 +2787,14 @@ Word16 IGF_getSFM( const Word32 *energy, /**< in: Q31| energies */ const Word16 *energy_exp, /**< in: | exponent of energies */ const Word16 start, /**< in: Q0 | start subband index */ +#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ +#else const Word16 stop /**< in: Q0 | stop subband index */ +#endif ); - +#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS /**< out: Q15| SFM value */ Word16 IGF_getSFM_ivas_fx( Word16 *SFM_exp, /**< out: | exponent of SFM Factor */ @@ -2798,6 +2803,7 @@ Word16 IGF_getSFM_ivas_fx( const Word16 start, /**< in: Q0 | start subband index */ const Word16 stop /**< in: Q0 | stop subband index */ ); +#endif /* IGFEnc.c */ void IGF_ErodeSpectrum( -- GitLab From 5752fe2cb96978213fdb8dce6be121991fc7d701 Mon Sep 17 00:00:00 2001 From: Michael Sturm Date: Wed, 11 Feb 2026 17:56:55 +0100 Subject: [PATCH 22/22] Adds clang format check fixes. --- lib_com/prot_fx.h | 2 +- lib_enc/igf_enc_fx.c | 45 +++++++++++++++++++++++-------------------- lib_enc/prot_fx_enc.h | 20 +++++++++---------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 537cae71a..b386a63a7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5430,7 +5430,7 @@ void IGFCommonFuncsMDCTSquareSpec( Word16 indexOffset, /**< in: Q0 | index offset */ const Word16 element_mode /**< in: | IVAS element mode type */ #else - Word16 indexOffset /**< in: Q0 | index offset */ + Word16 indexOffset /**< in: Q0 | index offset */ #endif ); diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index 121fd4868..487aa095c 100755 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -795,16 +795,16 @@ Word16 IGF_getCrest( /**< ou Word16 *crest_exp, /**< out: | exponent of crest factor */ const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ #else - const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ + const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ #endif - const Word16 start, /**< in: Q0 | start subband index */ + const Word16 start, /**< in: Q0 | start subband index */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 stop, /**< in: Q0 | stop subband index */ - const Word16 element_mode /**< in: | IVAS element mode type */ + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else - const Word16 stop /**< in: Q0 | stop subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ #endif ) { @@ -847,7 +847,7 @@ Word16 IGF_getCrest( /**< ou #else x = sub( sub( powerSpectrum_exp, norm_l( powerSpectrum[i] ) ), 1 ); /*Q0*/ #endif - if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ + if ( powerSpectrum[i] == 0 ) /*special case: energy is zero*/ { x = 0; move16(); @@ -990,7 +990,7 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value const Word16 stop, /**< in: Q0 | stop subband index */ const Word16 element_mode /**< in: | IVAS element mode type */ #else - const Word16 stop /**< in: Q0 | stop subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ #endif ) { @@ -1055,7 +1055,8 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value /* n = sub(n,31); */ /*<- -Qx */ /* n = add(n,*energy_exp); */ /*<- +xExp */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( GT_16( element_mode, EVS_MONO ) ) { + IF( GT_16( element_mode, EVS_MONO ) ) + { en_exp = energy_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */ } n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/ @@ -1073,7 +1074,8 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value num = L_add( num, L_deposit_l( n ) ); /*Q0*/ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( EQ_16( element_mode, EVS_MONO ) ) { + IF( EQ_16( element_mode, EVS_MONO ) ) + { W_denom = W_add( W_deposit32_l( energy[i] ), W_denom ); } ELSE @@ -1086,7 +1088,8 @@ Word16 IGF_getSFM( /**< out: Q15| SFM value } #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - IF( EQ_16( element_mode, EVS_MONO ) ) { + IF( EQ_16( element_mode, EVS_MONO ) ) + { denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/ denom_exp = add( denom_exp, en_exp ); } @@ -1789,10 +1792,10 @@ Word16 IGFEncWriteBitstream_fx( /**< ou Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - const Word16 element_mode /**< in: | IVAS element mode type */ + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ #endif ) { @@ -1817,10 +1820,10 @@ Word16 IGFEncWriteBitstream_fx( /**< ou igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag, /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - &igfAllZero, /* o: *igfAllZero */ + &igfAllZero, /* o: *igfAllZero */ element_mode ); /* i: IVAS element mode type */ #else - &igfAllZero ); /* o: *igfAllZero */ + &igfAllZero ); /* o: *igfAllZero */ #endif IGF_WriteWhiteningLevels_fx( hInstance, /* i: instance handle of IGF Encoder */ @@ -4416,11 +4419,11 @@ Word16 IGFEncWriteBitstream_ivas_fx( igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ #else - IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ - hBstr, /* i: encoder state */ - pBitOffset, /* i: ptr to bitOffset counter */ - igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ - isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ + IGF_WriteWhiteningLevels_ivas_fx( hIGFEnc, /* i: instance handle of IGF Encoder */ + hBstr, /* i: encoder state */ + pBitOffset, /* i: ptr to bitOffset counter */ + igfGridIdx, /* i: igf grid index see definition of IGF_GRID_IDX for details */ + isIndepFlag ); /* i: if 1 frame is independent, 0 = frame is coded with data from previous frame */ #endif #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 44b6f2b2f..0fe1ebe0a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2624,10 +2624,10 @@ Word16 IGFEncWriteBitstream_fx( Word16 *pBitOffset, /**< in: | ptr to bitOffset counter */ const Word16 igfGridIdx, /**< in: Q0 | igf grid index see declaration of IGF_GRID_IDX for details */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ - const Word16 element_mode /**< in: | IVAS element mode type */ + const Word16 isIndepFlag, /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else - const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ + const Word16 isIndepFlag /**< in: Q0 | if 1 frame is independent, 0 = frame is coded with data from previous frame */ #endif ); @@ -2755,17 +2755,17 @@ void IGF_UpdateInfo( /**< out: Q15| crest factor */ Word16 IGF_getCrest( - Word16 *crest_exp, /**< out: | exponent of crest factor */ - const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ + Word16 *crest_exp, /**< out: | exponent of crest factor */ + const Word32 *powerSpectrum, /**< in: Q31 | power spectrum */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 *powerSpectrum_exp,/**< in: | exponent of power spectrum */ + const Word16 *powerSpectrum_exp, /**< in: | exponent of power spectrum */ #else const Word16 powerSpectrum_exp, /**< in: | exponent of power spectrum */ #endif - const Word16 start, /**< in: Q0 | start subband index */ + const Word16 start, /**< in: Q0 | start subband index */ #ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS - const Word16 stop, /**< in: Q0 | stop subband index */ - const Word16 element_mode /**< in: | IVAS element mode type */ + const Word16 stop, /**< in: Q0 | stop subband index */ + const Word16 element_mode /**< in: | IVAS element mode type */ #else const Word16 stop /**< in: Q0 | stop subband index */ #endif @@ -2791,7 +2791,7 @@ Word16 IGF_getSFM( const Word16 stop, /**< in: Q0 | stop subband index */ const Word16 element_mode /**< in: | IVAS element mode type */ #else - const Word16 stop /**< in: Q0 | stop subband index */ + const Word16 stop /**< in: Q0 | stop subband index */ #endif ); #ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS -- GitLab