From 3f52fcd43ebd41a6aba2f2d2e4defbe952fba2d2 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 8 Apr 2026 10:47:40 +0200 Subject: [PATCH 01/11] add macro HARMONIZE_2508_GetAttackForTCXDecision and its code --- lib_com/options.h | 1 + lib_enc/stat_enc.h | 4 + lib_enc/transient_detection_fx.c | 145 ++++++++++++++++++++++++++----- 3 files changed, 130 insertions(+), 20 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index e628cf13d..698400275 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,6 +103,7 @@ #define HARMONIZE_DCT /* VA: removal of duplicated DCT functions */ #define FIX_2489_HARMONIZE_FdCng_encodeSID /* FhG: harmonize FdCng_encodeSID_fx() and FdCng_encodeSID_ivas_fx() */ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ +#define HARMONIZE_2508_GetAttackForTCXDecision /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 2ee4a05f2..78fe6ffc8 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -160,7 +160,11 @@ typedef struct /* Attack detection function. */ +#ifdef HARMONIZE_2508_GetAttackForTCXDecision +typedef void ( *TCheckSubblocksForAttack_fx )( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex, Word16 element_mode ); +#else typedef void ( *TCheckSubblocksForAttack_fx )( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex ); +#endif /* Transient detector. */ typedef struct TransientDetector diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index f671b8d9e..111f52c14 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -50,7 +50,11 @@ static void UpdateDelayBuffer( Word16 const *input, const Word16 nSamplesAvailab static void HighPassFilter_fx( Word16 const *input, const Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); static void UpdateSubblockEnergies( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void CalculateSubblockEnergies( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); +#ifdef HARMONIZE_2508_GetAttackForTCXDecision +static void RunTransientDetector_fx( TransientDetector *pTransientDetector, Word16 element_mode ); +#else static void RunTransientDetector_fx( TransientDetector *pTransientDetector ); +#endif static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); @@ -60,12 +64,12 @@ static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nS /* Functions that define transient detectors */ /* */ /************************************************/ - /** TCX decision. * Check IF there is an attack in a subblock. Version FOR TCX Long/Short decision. * See TCheckSubblocksForAttack_fx FOR definition of parameters. * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. */ +#ifndef HARMONIZE_2508_GetAttackForTCXDecision static void GetAttackForTCXDecision( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, @@ -146,9 +150,11 @@ static void GetAttackForTCXDecision( return; } +#endif /* GetAttackForTCXDecision() version using 32-bit for energy change values */ +#ifndef HARMONIZE_2508_GetAttackForTCXDecision static void GetAttackForTCXDecision_ivas_fx( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, @@ -157,11 +163,25 @@ static void GetAttackForTCXDecision_ivas_fx( Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex ) +#else +static void GetAttackForTCXDecision_fx( + Word32 const *pSubblockNrg, + Word32 const *pAccSubblockNrg, + Word16 nSubblocks, + Word16 nPastSubblocks, + Word16 attackRatioThreshold, + Word16 *pbIsAttackPresent, + Word16 *pAttackIndex, + Word16 element_mode ) +#endif { Word16 i; Word16 bIsAttackPresent, attackIndex; Word16 attackRatioThreshold_1_5; Word64 W_tmp1, W_tmp2, W_tmp3; +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + Word32 L_tmp1, L_tmp2, L_tmp3; +#endif assert( nSubblocks >= NSUBBLOCKS ); assert( nPastSubblocks >= 2 ); @@ -172,23 +192,53 @@ static void GetAttackForTCXDecision_ivas_fx( move16(); move16(); bIsAttackPresent = FALSE; +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + attackIndex = EQ_16( element_mode, EVS_MONO ) ? 0 : -1; +#else attackIndex = -1; +#endif /* Search for the last attack in the subblocks */ IF( s_or( (Word16) GT_32( L_shr( pSubblockNrg[-1], ATTACKTHRESHOLD_E ), Mpy_32_16_1( pAccSubblockNrg[-1], attackRatioThreshold ) ), L_sub( L_shr( pSubblockNrg[-2], ATTACKTHRESHOLD_E ), Mpy_32_16_1( pAccSubblockNrg[-2], attackRatioThreshold ) ) > 0 ) ) { move16(); bIsAttackPresent = TRUE; +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + if ( GT_32( element_mode, EVS_MONO ) ) + { + attackIndex = 0; + move16(); + } +#else attackIndex = 0; move16(); + +#endif } FOR( i = 0; i < NSUBBLOCKS; i++ ) { +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + int condition; + IF( EQ_16( element_mode, EVS_MONO ) ) + { + L_tmp2 = L_shr( pSubblockNrg[i], ATTACKTHRESHOLD_E ); + L_tmp1 = Mpy_32_16_1( pAccSubblockNrg[i], attackRatioThreshold ); + condition = GT_32( L_tmp2, L_tmp1 ); + } + ELSE + { + W_tmp2 = W_shr( W_mult_32_16( pAccSubblockNrg[i], attackRatioThreshold ), 1 ); + W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); + condition = GT_64( W_tmp1, W_tmp2 ); + } + IF( condition ) +#else W_tmp2 = W_shr( W_mult_32_16( pAccSubblockNrg[i], attackRatioThreshold ), 1 ); W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); IF( GT_64( W_tmp1, W_tmp2 ) ) +#endif { if ( i < 6 ) { @@ -200,23 +250,44 @@ static void GetAttackForTCXDecision_ivas_fx( { move16(); attackIndex = i; - W_tmp2 = W_shr( W_mult_32_16( pAccSubblockNrg[i], attackRatioThreshold ), 1 ); - W_tmp2 = W_add( W_tmp2, W_shr( W_tmp2, 3 ) ); // pAccSubblockNrg[i] * 1.125f - W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); - if ( s_and( (Word16) LT_64( W_tmp1, W_tmp2 ), s_or( (Word16) EQ_16( i, 2 ), (Word16) EQ_16( i, 6 ) ) ) ) +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + IF( GT_16( element_mode, EVS_MONO ) ) { - attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ +#endif + W_tmp2 = W_shr( W_mult_32_16( pAccSubblockNrg[i], attackRatioThreshold ), 1 ); + W_tmp2 = W_add( W_tmp2, W_shr( W_tmp2, 3 ) ); // pAccSubblockNrg[i] * 1.125f + W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); + if ( s_and( (Word16) LT_64( W_tmp1, W_tmp2 ), s_or( (Word16) EQ_16( i, 2 ), (Word16) EQ_16( i, 6 ) ) ) ) + { + attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ + } +#ifdef HARMONIZE_2508_GetAttackForTCXDecision } +#endif } } ELSE /* no attack, but set index anyway in case of strong energy increase */ { - W_tmp2 = W_shr( W_mult_32_16( pSubblockNrg[i - 1], attackRatioThreshold_1_5 ), 1 ); - W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ( ATTACKTHRESHOLD_E + 1 ) ) ); - W_tmp3 = W_shr( W_mult_32_16( pSubblockNrg[i - 2], attackRatioThreshold_1_5 ), 1 ); +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + IF( EQ_16( element_mode, EVS_MONO ) ) + { + L_tmp2 = Mpy_32_16_1( pSubblockNrg[i - 1], attackRatioThreshold_1_5 ); + L_tmp1 = L_shr( pSubblockNrg[i], 1 + ATTACKTHRESHOLD_E ); + L_tmp3 = Mpy_32_16_1( pSubblockNrg[i - 2], attackRatioThreshold_1_5 ); + condition = s_and( ( (Word16) GT_32( L_tmp1, L_tmp2 ) ), ( L_sub( L_tmp1, L_tmp3 ) > 0 ) ); + } + ELSE + { +#endif + W_tmp2 = W_shr( W_mult_32_16( pSubblockNrg[i - 1], attackRatioThreshold_1_5 ), 1 ); + W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ( ATTACKTHRESHOLD_E + 1 ) ) ); + W_tmp3 = W_shr( W_mult_32_16( pSubblockNrg[i - 2], attackRatioThreshold_1_5 ), 1 ); +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + condition = s_and( ( (Word16) GT_64( W_tmp1, W_tmp2 ) ), ( W_sub( W_tmp1, W_tmp3 ) > 0 ) ); + } - IF( s_and( ( (Word16) GT_64( W_tmp1, W_tmp2 ) ), - ( W_sub( W_tmp1, W_tmp3 ) > 0 ) ) ) + IF( condition ) +#endif { IF( s_and( (Word16) NE_16( attackIndex, 2 ), (Word16) NE_16( attackIndex, 6 ) ) ) @@ -224,16 +295,22 @@ static void GetAttackForTCXDecision_ivas_fx( move16(); attackIndex = i; - W_tmp2 = W_mult_32_16( pSubblockNrg[i - 1], attackRatioThreshold ); - W_tmp3 = W_mult_32_16( pSubblockNrg[i - 2], attackRatioThreshold ); - W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); - - if ( s_and( (Word16) s_or( (Word16) LT_64( W_tmp1, W_tmp2 ), (Word16) - LT_64( W_tmp1, W_tmp3 ) ), - s_or( (Word16) EQ_16( i, 2 ), (Word16) EQ_16( i, 6 ) ) ) ) +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + IF( GT_32( element_mode, EVS_MONO ) ) { - attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ +#endif + W_tmp2 = W_mult_32_16( pSubblockNrg[i - 1], attackRatioThreshold ); + W_tmp3 = W_mult_32_16( pSubblockNrg[i - 2], attackRatioThreshold ); + W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); + + if ( s_and( (Word16) s_or( (Word16) LT_64( W_tmp1, W_tmp2 ), (Word16) LT_64( W_tmp1, W_tmp3 ) ), + s_or( (Word16) EQ_16( i, 2 ), (Word16) EQ_16( i, 6 ) ) ) ) + { + attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ + } +#ifdef HARMONIZE_2508_GetAttackForTCXDecision } +#endif } } } @@ -267,7 +344,11 @@ static void InitTCXTransientDetector( SubblockEnergies *pSubblockEnergies, TransientDetector *pTransientDetector ) { +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + InitTransientDetector_fx( pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector ); +#else InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); +#endif /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ @@ -607,7 +692,11 @@ void RunTransientDetection_fx( UpdateSubblockEnergies( filteredInput, nSamplesAvailable, pSubblockEnergies ); /* Run transient detectors. */ +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + RunTransientDetector_fx( pTransientDetector, EVS_MONO ); +#else RunTransientDetector_fx( pTransientDetector ); +#endif /* Update the delay buffer. */ UpdateDelayBuffer( filteredInput, nSamplesAvailable, &hTranDet->delayBuffer ); @@ -678,7 +767,11 @@ void RunTransientDetection_ivas_fx( UpdateSubblockEnergies_ivas_fx( filteredInput_fx, length, pSubblockEnergies ); /* Run transient detectors. */ +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + RunTransientDetector_fx( pTransientDetector, 1 ); +#else RunTransientDetector_fx( pTransientDetector ); +#endif /* Update the delay buffer. */ UpdateDelayBuffer( filteredInput_fx, length, &hTranDet->delayBuffer ); @@ -1277,9 +1370,14 @@ static void HighPassFilter_fx( return; } - +#ifdef HARMONIZE_2508_GetAttackForTCXDecision +static void RunTransientDetector_fx( + TransientDetector *pTransientDetector, + Word16 element_mode) +#else static void RunTransientDetector_fx( TransientDetector *pTransientDetector ) +#endif { Word16 const attackRatioThreshold = pTransientDetector->attackRatioThreshold; move16(); @@ -1294,10 +1392,17 @@ static void RunTransientDetector_fx( assert( ( pTransientDetector->CheckSubblocksForAttack_fx != NULL ) ); #define WMC_TOOL_SKIP +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + pTransientDetector->CheckSubblocksForAttack_fx( pSubblockNrg, pAccSubblockNrg, + NSUBBLOCKS + nDelay, nRelativeDelay, + attackRatioThreshold, + &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex, element_mode ); +#else pTransientDetector->CheckSubblocksForAttack_fx( pSubblockNrg, pAccSubblockNrg, NSUBBLOCKS + nDelay, nRelativeDelay, attackRatioThreshold, &pTransientDetector->bIsAttackPresent, &pTransientDetector->attackIndex ); +#endif #undef WMC_TOOL_SKIP return; -- GitLab From e4fe6183f7f66bf2faaf224d998fbffb1b94b4e8 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 8 Apr 2026 10:56:44 +0200 Subject: [PATCH 02/11] clang format check --- lib_enc/transient_detection_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 111f52c14..4ff93ace9 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -1373,7 +1373,7 @@ static void HighPassFilter_fx( #ifdef HARMONIZE_2508_GetAttackForTCXDecision static void RunTransientDetector_fx( TransientDetector *pTransientDetector, - Word16 element_mode) + Word16 element_mode ) #else static void RunTransientDetector_fx( TransientDetector *pTransientDetector ) -- GitLab From bd0d56df51002421bb61b2a94a44be472273da55 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 8 Apr 2026 12:12:48 +0200 Subject: [PATCH 03/11] add macro and code HARMONIZE_2508_InitSubblockEnergies --- lib_com/options.h | 1 + lib_enc/transient_detection_fx.c | 59 ++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 698400275..290c98f4e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -104,6 +104,7 @@ #define FIX_2489_HARMONIZE_FdCng_encodeSID /* FhG: harmonize FdCng_encodeSID_fx() and FdCng_encodeSID_ivas_fx() */ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ #define HARMONIZE_2508_GetAttackForTCXDecision /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ +#define HARMONIZE_2508_InitSubblockEnergies /* FhG: harmonize InitSubblockEnergies derivates for evs/ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 4ff93ace9..bd5902b51 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -42,8 +42,12 @@ /************************************************/ static void InitDelayBuffer( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer ); +#ifdef HARMONIZE_2508_InitSubblockEnergies +static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies, Word16 element_mode ); +#else static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitSubblockEnergies_ivas_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); +#endif static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void InitTransientDetector_ivas_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void UpdateDelayBuffer( Word16 const *input, const Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); @@ -369,7 +373,11 @@ void InitTransientDetection_fx( InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); /* Init a subblock energies buffer used for the TCX Short/Long decision. */ +#ifdef HARMONIZE_2508_InitSubblockEnergies + InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); +#else InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); +#endif /* Init the TCX Short/Long transient detector. */ InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); @@ -393,7 +401,11 @@ void InitTransientDetection_ivas_fx( /* Init a subblock energies buffer used for the TCX Short/Long decision. */ +#ifdef HARMONIZE_2508_InitSubblockEnergies + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 ); +#else InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); +#endif /* Init the TCX Short/Long transient detector. */ @@ -1157,7 +1169,7 @@ static void InitDelayBuffer( return; } - +#ifndef HARMONIZE_2508_InitSubblockEnergies static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, @@ -1189,33 +1201,55 @@ static void InitSubblockEnergies( return; } +#endif +#ifdef HARMONIZE_2508_InitSubblockEnergies +static void InitSubblockEnergies_fx( + const Word16 nFrameLength, + const Word16 nDelay, + DelayBuffer *pDelayBuffer, + SubblockEnergies *pSubblockEnergies, + Word16 element_mode ) +#else static void InitSubblockEnergies_ivas_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ) +#endif { - Word16 const nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; - move16(); - assert( ( pDelayBuffer != NULL ) && ( pSubblockEnergies != NULL ) && ( pDelayBuffer->nSubblockSize * NSUBBLOCKS == nFrameLength ) && ( pDelayBuffer->nSubblockSize > 0 ) ); - set32_fx( pSubblockEnergies->subblockNrg, 54 /* 107.37 in Q(-1) */, nMaxBuffSize ); - set32_fx( pSubblockEnergies->accSubblockNrg, 54 /* 107.37 in Q(-1) */, nMaxBuffSize + 1 ); - set32_fx( pSubblockEnergies->subblockNrgChange_32fx, ONE_IN_Q15, nMaxBuffSize ); - set16_fx( pSubblockEnergies->subblockNrgChange_exp, 16, nMaxBuffSize ); - IF( nDelay != 0 ) + Word16 nMaxBuffSize; + +#ifdef HARMONIZE_2508_InitSubblockEnergies + IF( EQ_16( element_mode, EVS_MONO ) ) { - pSubblockEnergies->nDelay = idiv1616( nDelay, pDelayBuffer->nSubblockSize ); + nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); move16(); + + set32_fx( pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); + set16_fx( pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize ); } ELSE { - pSubblockEnergies->nDelay = 0; +#endif + nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; move16(); + + + set32_fx( pSubblockEnergies->subblockNrg, 54 /* 107.37 in Q(-1) */, nMaxBuffSize ); + set32_fx( pSubblockEnergies->accSubblockNrg, 54 /* 107.37 in Q(-1) */, nMaxBuffSize + 1 ); + set32_fx( pSubblockEnergies->subblockNrgChange_32fx, ONE_IN_Q15, nMaxBuffSize ); + set16_fx( pSubblockEnergies->subblockNrgChange_exp, 16, nMaxBuffSize ); + pSubblockEnergies->q_firState = 15; + move16(); +#ifdef HARMONIZE_2508_InitSubblockEnergies } +#endif + pSubblockEnergies->nDelay = idiv1616_1( nDelay, pDelayBuffer->nSubblockSize ); assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; move16(); @@ -1225,8 +1259,6 @@ static void InitSubblockEnergies_ivas_fx( move16(); pSubblockEnergies->firState2 = 0; move16(); - pSubblockEnergies->q_firState = 15; - move16(); pSubblockEnergies->pDelayBuffer = pDelayBuffer; pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); @@ -1235,7 +1267,6 @@ static void InitSubblockEnergies_ivas_fx( return; } - /** Init transient detector. * Fills TransientDetector structure with sensible content and enable it. * @param pSubblockEnergies Subblock energies used in this transient detector. -- GitLab From c8c7d5d0105bc641ca08603c8ae81479514f822a Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 8 Apr 2026 12:33:07 +0200 Subject: [PATCH 04/11] fix build error --- lib_enc/transient_detection_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index bd5902b51..4c6dc2061 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -43,7 +43,7 @@ static void InitDelayBuffer( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer ); #ifdef HARMONIZE_2508_InitSubblockEnergies -static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies, Word16 element_mode ); +static void InitSubblockEnergies_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies, Word16 element_mode ); #else static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitSubblockEnergies_ivas_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); @@ -374,7 +374,7 @@ void InitTransientDetection_fx( /* Init a subblock energies buffer used for the TCX Short/Long decision. */ #ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); #else InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); #endif @@ -402,7 +402,7 @@ void InitTransientDetection_ivas_fx( /* Init a subblock energies buffer used for the TCX Short/Long decision. */ #ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 ); + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 ); #else InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); #endif -- GitLab From b9d5c8e7cd244e955794ea24fdda5fb6f90c69a2 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 9 Apr 2026 09:18:34 +0200 Subject: [PATCH 05/11] add macro HARMONIZE_2508_InitTransientDetector and code --- lib_com/options.h | 1 + lib_enc/transient_detection_fx.c | 62 ++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 290c98f4e..e833b06b3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -105,6 +105,7 @@ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ #define HARMONIZE_2508_GetAttackForTCXDecision /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ #define HARMONIZE_2508_InitSubblockEnergies /* FhG: harmonize InitSubblockEnergies derivates for evs/ivas */ +#define HARMONIZE_2508_InitTransientDetector /* FhG: harmonize InitTransientDetector derivates for evs/ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 4c6dc2061..990a4f492 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -48,8 +48,12 @@ static void InitSubblockEnergies_fx( const Word16 nFrameLength, const Word16 nDe static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitSubblockEnergies_ivas_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); #endif +#ifdef HARMONIZE_2508_InitTransientDetector +static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector, Word16 element_mode ); +#else static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void InitTransientDetector_ivas_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); +#endif static void UpdateDelayBuffer( Word16 const *input, const Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter_fx( Word16 const *input, const Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); static void UpdateSubblockEnergies( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); @@ -348,11 +352,19 @@ static void InitTCXTransientDetector( SubblockEnergies *pSubblockEnergies, TransientDetector *pTransientDetector ) { +#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + InitTransientDetector_fx( pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<delayBuffer, &hTranDet->subblockEnergies, 1 ); + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 /*signal non-evs*/ ); #else InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); #endif /* Init the TCX Short/Long transient detector. */ +#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); +#else + InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); +#endif +#else #ifdef HARMONIZE_2508_GetAttackForTCXDecision InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector ); #else InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); #endif +#endif /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ @@ -1277,6 +1297,7 @@ static void InitSubblockEnergies_ivas_fx( * @param attackRatioThreshold Attack ratio threshold with exponent ATTACKTHRESHOLD_E. * @param pTransientDetector Structure to be initialized. */ +#ifndef HARMONIZE_2508_InitTransientDetector static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, @@ -1312,8 +1333,18 @@ static void InitTransientDetector_fx( return; } +#endif - +#ifdef HARMONIZE_2508_InitTransientDetector +static void InitTransientDetector_fx( + SubblockEnergies *pSubblockEnergies, + const Word16 nDelay, + const Word16 nSubblocksToCheck, + const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, + const Word16 attackRatioThreshold, + TransientDetector *pTransientDetector, + Word16 element_mode ) +#else static void InitTransientDetector_ivas_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, @@ -1321,7 +1352,25 @@ static void InitTransientDetector_ivas_fx( const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ) +#endif { +#ifdef HARMONIZE_2508_InitTransientDetector + Word16 nMaxBuffSize; + IF( EQ_32( element_mode, EVS_MONO ) ) + { + nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + } + ELSE + { + nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; + move16(); + } + + assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); + pTransientDetector->pSubblockEnergies = pSubblockEnergies; + pTransientDetector->nDelay = idiv1616( sub( nDelay, pSubblockEnergies->nPartialDelay ), pSubblockEnergies->pDelayBuffer->nSubblockSize ); + move16(); +#else const Word16 nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; move16(); @@ -1337,6 +1386,7 @@ static void InitTransientDetector_ivas_fx( pTransientDetector->nDelay = 0; move16(); } +#endif assert( nDelay == pTransientDetector->nDelay * pSubblockEnergies->pDelayBuffer->nSubblockSize + pSubblockEnergies->nPartialDelay ); assert( pTransientDetector->nDelay < nMaxBuffSize ); pSubblockEnergies->nDelay = s_max( pSubblockEnergies->nDelay, pTransientDetector->nDelay ); @@ -1353,9 +1403,17 @@ static void InitTransientDetector_ivas_fx( move16(); pTransientDetector->attackIndex = -1; move16(); +#ifdef HARMONIZE_2508_InitTransientDetector + IF( GT_32( element_mode, EVS_MONO ) ) + { + pTransientDetector->pSubblockEnergies->ramp_up_flag = 0x0; + move16(); + } +#else pTransientDetector->pSubblockEnergies->ramp_up_flag = 0x0; move16(); +#endif return; } -- GitLab From d5dabca0a009a3e38896ae0254930554afde1104 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 9 Apr 2026 09:33:22 +0200 Subject: [PATCH 06/11] clang format patch --- lib_enc/transient_detection_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 990a4f492..d21e13dd7 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -364,7 +364,7 @@ static void InitTCXTransientDetector( #else InitTransientDetector_fx( pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision, 17408 /*8.5f/(1< Date: Thu, 9 Apr 2026 10:17:17 +0200 Subject: [PATCH 07/11] bugfix --- lib_enc/transient_detection_fx.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index d21e13dd7..d11b4f3db 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -1356,20 +1356,32 @@ static void InitTransientDetector_ivas_fx( { #ifdef HARMONIZE_2508_InitTransientDetector Word16 nMaxBuffSize; - IF( EQ_32( element_mode, EVS_MONO ) ) + IF( EQ_16( element_mode, EVS_MONO ) ) { nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + move16(); + assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); + pTransientDetector->pSubblockEnergies = pSubblockEnergies; + pTransientDetector->nDelay = ( nDelay - pSubblockEnergies->nPartialDelay ) / pSubblockEnergies->pDelayBuffer->nSubblockSize; } ELSE { nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; move16(); + assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); + pTransientDetector->pSubblockEnergies = pSubblockEnergies; + IF( sub( nDelay, pSubblockEnergies->nPartialDelay ) != 0 ) + { + pTransientDetector->nDelay = idiv1616( sub( nDelay, pSubblockEnergies->nPartialDelay ), pSubblockEnergies->pDelayBuffer->nSubblockSize ); + move16(); + } + ELSE + { + pTransientDetector->nDelay = 0; + move16(); + } } - assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); - pTransientDetector->pSubblockEnergies = pSubblockEnergies; - pTransientDetector->nDelay = idiv1616( sub( nDelay, pSubblockEnergies->nPartialDelay ), pSubblockEnergies->pDelayBuffer->nSubblockSize ); - move16(); #else const Word16 nMaxBuffSize = NSUBBLOCKS + MAX_TD_DELAY; move16(); @@ -1404,7 +1416,7 @@ static void InitTransientDetector_ivas_fx( pTransientDetector->attackIndex = -1; move16(); #ifdef HARMONIZE_2508_InitTransientDetector - IF( GT_32( element_mode, EVS_MONO ) ) + IF( GT_16( element_mode, EVS_MONO ) ) { pTransientDetector->pSubblockEnergies->ramp_up_flag = 0x0; move16(); -- GitLab From 3a15a1e371b13854e1fc969129c4e3efb8c59299 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 9 Apr 2026 11:13:11 +0200 Subject: [PATCH 08/11] added macro HARMONIZE_2508_InitTransientDetection and code --- lib_com/options.h | 1 + lib_enc/init_enc_fx.c | 17 ++++++++ lib_enc/ivas_mct_enc_fx.c | 5 ++- lib_enc/prot_fx_enc.h | 9 ++++ lib_enc/transient_detection_fx.c | 72 ++++++++++++++++++++++++++++++-- 5 files changed, 99 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index e833b06b3..9648c247a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -106,6 +106,7 @@ #define HARMONIZE_2508_GetAttackForTCXDecision /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ #define HARMONIZE_2508_InitSubblockEnergies /* FhG: harmonize InitSubblockEnergies derivates for evs/ivas */ #define HARMONIZE_2508_InitTransientDetector /* FhG: harmonize InitTransientDetector derivates for evs/ivas */ +#define HARMONIZE_2508_InitTransientDetection /* FhG: harmonize InitTransientDetection derivates for evs/ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index a8315f555..ee40a15bc 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1200,6 +1200,22 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } +#ifdef HARMONIZE_2508_InitTransientDetection + { + Word16 nTCXDelay = 0; + move16(); + Word16 ext_mem_flag = 1; + move16(); + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + nTCXDelay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); + ext_mem_flag = 0; + } + + InitTransientDetection_fx( input_frame, nTCXDelay, st->hTranDet, ext_mem_flag, st->element_mode ); + } +#else IF( GT_16( st->element_mode, EVS_MONO ) ) { InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); @@ -1208,6 +1224,7 @@ ivas_error init_encoder_fx( { InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); } +#endif /*-----------------------------------------------------------------* * IVAS parameters diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 091b8c6b2..28040acdf 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -1184,8 +1184,11 @@ static ivas_error ivas_mc_enc_reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - +#ifdef HARMONIZE_2508_InitTransientDetection + InitTransientDetection_fx( extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0, st->element_mode ); +#else InitTransientDetection_ivas_fx( extract_l( Mult_32_16( st->input_Fs, INV_FRAME_PER_SEC_Q15 ) ), NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0 ); +#endif } IF( st->hIGFEnc == NULL ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index f5f2d2dcf..ee2a03ca7 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -878,6 +878,14 @@ void calculate_hangover_attenuation_gain_fx( * Don't include the delay of the MDCT overlap. * @param pTransientDetection Structure to be initialized. It contains all transient detectors to be used. */ +#ifdef HARMONIZE_2508_InitTransientDetection +void InitTransientDetection_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet, + const Word16 ext_mem_flag, + Word16 element_mode ); +#else void InitTransientDetection_fx( const Word16 nFrameLength, const Word16 nTCXDelay, @@ -888,6 +896,7 @@ void InitTransientDetection_ivas_fx( const Word16 nTCXDelay, TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ); +#endif /** Runs transient detection. * Runs all transient detectors defined in pTransientDetection diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index d11b4f3db..9740a2c7c 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -375,7 +375,7 @@ static void InitTCXTransientDetector( /* Interface functions */ /* */ /************************************************/ - +#ifndef HARMONIZE_2508_InitTransientDetection void InitTransientDetection_fx( const Word16 nFrameLength, const Word16 nTCXDelay, @@ -400,27 +400,75 @@ void InitTransientDetection_fx( return; } +#endif - +#ifdef HARMONIZE_2508_InitTransientDetection +void InitTransientDetection_fx( + const Word16 nFrameLength, + const Word16 nTCXDelay, + TRAN_DET_HANDLE hTranDet, + const Word16 ext_mem_flag, + Word16 element_mode ) +#else void InitTransientDetection_ivas_fx( const Word16 nFrameLength, const Word16 nTCXDelay, TRAN_DET_HANDLE hTranDet, const Word16 ext_mem_flag ) +#endif { /* Init the delay buffer. */ InitDelayBuffer( nFrameLength, nTCXDelay, &hTranDet->delayBuffer ); - /* Init a subblock energies buffer used for the TCX Short/Long decision. */ +#ifdef HARMONIZE_2508_InitTransientDetection + IF( EQ_16( element_mode, EVS_MONO ) ) + { +#ifdef HARMONIZE_2508_InitSubblockEnergies + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); +#else + InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); +#endif + } + ELSE + { +#ifdef HARMONIZE_2508_InitSubblockEnergies + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 /*signal non-evs*/ ); +#else + InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); +#endif + } +#else #ifdef HARMONIZE_2508_InitSubblockEnergies InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 /*signal non-evs*/ ); #else InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); #endif - +#endif /* Init the TCX Short/Long transient detector. */ +#ifdef HARMONIZE_2508_InitTransientDetection + IF( EQ_16( element_mode, EVS_MONO ) ) + { + InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); + } + ELSE + { +#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); +#else + InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); +#endif +#else +#ifdef HARMONIZE_2508_GetAttackForTCXDecision + InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector ); +#else + InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); +#endif +#endif + } +#else #ifdef HARMONIZE_2508_InitTransientDetector #ifdef HARMONIZE_2508_GetAttackForTCXDecision InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); @@ -434,9 +482,24 @@ void InitTransientDetection_ivas_fx( InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); #endif #endif +#endif /*HARMONIZE_2508_InitTransientDetection*/ /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ +#ifdef HARMONIZE_2508_InitTransientDetection + IF( ext_mem_flag && GT_32( element_mode, EVS_MONO ) ) + { + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); + move16(); + } + ELSE + { + hTranDet->transientDetector.pSubblockEnergies->nDelay = + add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); + move16(); + } +#else IF( ext_mem_flag ) { hTranDet->transientDetector.pSubblockEnergies->nDelay = @@ -449,6 +512,7 @@ void InitTransientDetection_ivas_fx( add( hTranDet->transientDetector.pSubblockEnergies->nDelay, NSUBBLOCKS + 1 ); move16(); } +#endif return; } -- GitLab From f7f0b85543603489891d1bcbd72562c858baffa0 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 9 Apr 2026 12:02:04 +0200 Subject: [PATCH 09/11] straighten macros --- lib_com/options.h | 5 +- lib_enc/stat_enc.h | 2 +- lib_enc/transient_detection_fx.c | 137 ++++++++----------------------- 3 files changed, 35 insertions(+), 109 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9648c247a..7769e50c6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,10 +103,7 @@ #define HARMONIZE_DCT /* VA: removal of duplicated DCT functions */ #define FIX_2489_HARMONIZE_FdCng_encodeSID /* FhG: harmonize FdCng_encodeSID_fx() and FdCng_encodeSID_ivas_fx() */ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ -#define HARMONIZE_2508_GetAttackForTCXDecision /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ -#define HARMONIZE_2508_InitSubblockEnergies /* FhG: harmonize InitSubblockEnergies derivates for evs/ivas */ -#define HARMONIZE_2508_InitTransientDetector /* FhG: harmonize InitTransientDetector derivates for evs/ivas */ -#define HARMONIZE_2508_InitTransientDetection /* FhG: harmonize InitTransientDetection derivates for evs/ivas */ +#define HARMONIZE_2508_InitTransientDetection /* FhG: harmonize GetAttackForTCXDecision derivates for evs/ivas */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 78fe6ffc8..62e49a5a3 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -160,7 +160,7 @@ typedef struct /* Attack detection function. */ -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection typedef void ( *TCheckSubblocksForAttack_fx )( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex, Word16 element_mode ); #else typedef void ( *TCheckSubblocksForAttack_fx )( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, Word16 nSubblocks, Word16 nPastSubblocks, Word16 attackRatioThreshold, Word16 *pbIsAttackPresent, Word16 *pAttackIndex ); diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 9740a2c7c..2c32b2d26 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -42,27 +42,21 @@ /************************************************/ static void InitDelayBuffer( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer ); -#ifdef HARMONIZE_2508_InitSubblockEnergies +#ifdef HARMONIZE_2508_InitTransientDetection static void InitSubblockEnergies_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies, Word16 element_mode ); +static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector, Word16 element_mode ); +static void RunTransientDetector_fx( TransientDetector *pTransientDetector, Word16 element_mode ); #else static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); static void InitSubblockEnergies_ivas_fx( const Word16 nFrameLength, const Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ); -#endif -#ifdef HARMONIZE_2508_InitTransientDetector -static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector, Word16 element_mode ); -#else static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); static void InitTransientDetector_ivas_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, const Word16 nSubblocksToCheck, const TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, const Word16 attackRatioThreshold, TransientDetector *pTransientDetector ); +static void RunTransientDetector_fx( TransientDetector *pTransientDetector ); #endif static void UpdateDelayBuffer( Word16 const *input, const Word16 nSamplesAvailable, DelayBuffer *pDelayBuffer ); static void HighPassFilter_fx( Word16 const *input, const Word16 length, Word16 *pFirState1, Word16 *pFirState2, Word16 *output ); static void UpdateSubblockEnergies( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void CalculateSubblockEnergies( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); -#ifdef HARMONIZE_2508_GetAttackForTCXDecision -static void RunTransientDetector_fx( TransientDetector *pTransientDetector, Word16 element_mode ); -#else -static void RunTransientDetector_fx( TransientDetector *pTransientDetector ); -#endif static void CalculateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nSamplesAvailable, SubblockEnergies *pSubblockEnergies ); @@ -77,7 +71,7 @@ static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nS * See TCheckSubblocksForAttack_fx FOR definition of parameters. * It is assumed that the delay of MDCT overlap was not taken into account, so that the last subblock corresponds to the newest input subblock. */ -#ifndef HARMONIZE_2508_GetAttackForTCXDecision +#ifndef HARMONIZE_2508_InitTransientDetection static void GetAttackForTCXDecision( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, @@ -162,7 +156,7 @@ static void GetAttackForTCXDecision( /* GetAttackForTCXDecision() version using 32-bit for energy change values */ -#ifndef HARMONIZE_2508_GetAttackForTCXDecision +#ifndef HARMONIZE_2508_InitTransientDetection static void GetAttackForTCXDecision_ivas_fx( Word32 const *pSubblockNrg, Word32 const *pAccSubblockNrg, @@ -187,7 +181,7 @@ static void GetAttackForTCXDecision_fx( Word16 bIsAttackPresent, attackIndex; Word16 attackRatioThreshold_1_5; Word64 W_tmp1, W_tmp2, W_tmp3; -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection Word32 L_tmp1, L_tmp2, L_tmp3; #endif @@ -200,7 +194,7 @@ static void GetAttackForTCXDecision_fx( move16(); move16(); bIsAttackPresent = FALSE; -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection attackIndex = EQ_16( element_mode, EVS_MONO ) ? 0 : -1; #else attackIndex = -1; @@ -211,7 +205,7 @@ static void GetAttackForTCXDecision_fx( { move16(); bIsAttackPresent = TRUE; -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection if ( GT_32( element_mode, EVS_MONO ) ) { attackIndex = 0; @@ -226,7 +220,7 @@ static void GetAttackForTCXDecision_fx( FOR( i = 0; i < NSUBBLOCKS; i++ ) { -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection int condition; IF( EQ_16( element_mode, EVS_MONO ) ) { @@ -258,7 +252,7 @@ static void GetAttackForTCXDecision_fx( { move16(); attackIndex = i; -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection IF( GT_16( element_mode, EVS_MONO ) ) { #endif @@ -269,14 +263,14 @@ static void GetAttackForTCXDecision_fx( { attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ } -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection } #endif } } ELSE /* no attack, but set index anyway in case of strong energy increase */ { -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection IF( EQ_16( element_mode, EVS_MONO ) ) { L_tmp2 = Mpy_32_16_1( pSubblockNrg[i - 1], attackRatioThreshold_1_5 ); @@ -290,7 +284,7 @@ static void GetAttackForTCXDecision_fx( W_tmp2 = W_shr( W_mult_32_16( pSubblockNrg[i - 1], attackRatioThreshold_1_5 ), 1 ); W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ( ATTACKTHRESHOLD_E + 1 ) ) ); W_tmp3 = W_shr( W_mult_32_16( pSubblockNrg[i - 2], attackRatioThreshold_1_5 ), 1 ); -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection condition = s_and( ( (Word16) GT_64( W_tmp1, W_tmp2 ) ), ( W_sub( W_tmp1, W_tmp3 ) > 0 ) ); } @@ -303,7 +297,7 @@ static void GetAttackForTCXDecision_fx( move16(); attackIndex = i; -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection IF( GT_32( element_mode, EVS_MONO ) ) { #endif @@ -316,7 +310,7 @@ static void GetAttackForTCXDecision_fx( { attackIndex = add( attackIndex, 1 ); /* avoid minimum overlap to prevent clicks */ } -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection } #endif } @@ -344,6 +338,7 @@ static void GetAttackForTCXDecision_fx( } +#ifndef HARMONIZE_2508_InitTransientDetection /** Initialize TCX transient detector. * See InitTransientDetector_fx for definition of parameters. */ @@ -352,22 +347,10 @@ static void InitTCXTransientDetector( SubblockEnergies *pSubblockEnergies, TransientDetector *pTransientDetector ) { -#ifdef HARMONIZE_2508_InitTransientDetector -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - InitTransientDetector_fx( pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<delayBuffer ); /* Init a subblock energies buffer used for the TCX Short/Long decision. */ -#ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); -#else InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); -#endif /* Init the TCX Short/Long transient detector. */ InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); @@ -422,66 +401,16 @@ void InitTransientDetection_ivas_fx( /* Init a subblock energies buffer used for the TCX Short/Long decision. */ #ifdef HARMONIZE_2508_InitTransientDetection - IF( EQ_16( element_mode, EVS_MONO ) ) - { -#ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, EVS_MONO ); -#else - InitSubblockEnergies( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); -#endif - } - ELSE - { -#ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 /*signal non-evs*/ ); -#else - InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); -#endif - } -#else -#ifdef HARMONIZE_2508_InitSubblockEnergies - InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, 1 /*signal non-evs*/ ); + InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, element_mode ); #else InitSubblockEnergies_ivas_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies ); -#endif #endif /* Init the TCX Short/Long transient detector. */ #ifdef HARMONIZE_2508_InitTransientDetection - IF( EQ_16( element_mode, EVS_MONO ) ) - { - InitTCXTransientDetector( nTCXDelay, &hTranDet->subblockEnergies, &hTranDet->transientDetector ); - } - ELSE - { -#ifdef HARMONIZE_2508_InitTransientDetector -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); -#else - InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); -#endif -#else -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector ); -#else - InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); -#endif -#endif - } -#else -#ifdef HARMONIZE_2508_InitTransientDetector -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); -#else - InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector, 1 /*signal non-evs*/ ); -#endif -#else -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector ); + InitTransientDetector_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_fx, 17408 /*8.5f/(1<transientDetector, element_mode ); #else InitTransientDetector_ivas_fx( &hTranDet->subblockEnergies, nTCXDelay, NSUBBLOCKS, GetAttackForTCXDecision_ivas_fx, 17408 /*8.5f/(1<transientDetector ); -#endif -#endif #endif /*HARMONIZE_2508_InitTransientDetection*/ @@ -788,7 +717,7 @@ void RunTransientDetection_fx( UpdateSubblockEnergies( filteredInput, nSamplesAvailable, pSubblockEnergies ); /* Run transient detectors. */ -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection RunTransientDetector_fx( pTransientDetector, EVS_MONO ); #else RunTransientDetector_fx( pTransientDetector ); @@ -863,8 +792,8 @@ void RunTransientDetection_ivas_fx( UpdateSubblockEnergies_ivas_fx( filteredInput_fx, length, pSubblockEnergies ); /* Run transient detectors. */ -#ifdef HARMONIZE_2508_GetAttackForTCXDecision - RunTransientDetector_fx( pTransientDetector, 1 ); +#ifdef HARMONIZE_2508_InitTransientDetection + RunTransientDetector_fx( pTransientDetector, 1 /*signal non-EVS*/ ); #else RunTransientDetector_fx( pTransientDetector ); #endif @@ -1253,7 +1182,7 @@ static void InitDelayBuffer( return; } -#ifndef HARMONIZE_2508_InitSubblockEnergies +#ifndef HARMONIZE_2508_InitTransientDetection static void InitSubblockEnergies( const Word16 nFrameLength, const Word16 nDelay, @@ -1288,7 +1217,7 @@ static void InitSubblockEnergies( #endif -#ifdef HARMONIZE_2508_InitSubblockEnergies +#ifdef HARMONIZE_2508_InitTransientDetection static void InitSubblockEnergies_fx( const Word16 nFrameLength, const Word16 nDelay, @@ -1307,7 +1236,7 @@ static void InitSubblockEnergies_ivas_fx( Word16 nMaxBuffSize; -#ifdef HARMONIZE_2508_InitSubblockEnergies +#ifdef HARMONIZE_2508_InitTransientDetection IF( EQ_16( element_mode, EVS_MONO ) ) { nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); @@ -1330,7 +1259,7 @@ static void InitSubblockEnergies_ivas_fx( set16_fx( pSubblockEnergies->subblockNrgChange_exp, 16, nMaxBuffSize ); pSubblockEnergies->q_firState = 15; move16(); -#ifdef HARMONIZE_2508_InitSubblockEnergies +#ifdef HARMONIZE_2508_InitTransientDetection } #endif pSubblockEnergies->nDelay = idiv1616_1( nDelay, pDelayBuffer->nSubblockSize ); @@ -1361,7 +1290,7 @@ static void InitSubblockEnergies_ivas_fx( * @param attackRatioThreshold Attack ratio threshold with exponent ATTACKTHRESHOLD_E. * @param pTransientDetector Structure to be initialized. */ -#ifndef HARMONIZE_2508_InitTransientDetector +#ifndef HARMONIZE_2508_InitTransientDetection static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, @@ -1399,7 +1328,7 @@ static void InitTransientDetector_fx( } #endif -#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_InitTransientDetection static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, const Word16 nDelay, @@ -1418,7 +1347,7 @@ static void InitTransientDetector_ivas_fx( TransientDetector *pTransientDetector ) #endif { -#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_InitTransientDetection Word16 nMaxBuffSize; IF( EQ_16( element_mode, EVS_MONO ) ) { @@ -1479,7 +1408,7 @@ static void InitTransientDetector_ivas_fx( move16(); pTransientDetector->attackIndex = -1; move16(); -#ifdef HARMONIZE_2508_InitTransientDetector +#ifdef HARMONIZE_2508_InitTransientDetection IF( GT_16( element_mode, EVS_MONO ) ) { pTransientDetector->pSubblockEnergies->ramp_up_flag = 0x0; @@ -1535,7 +1464,7 @@ static void HighPassFilter_fx( return; } -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection static void RunTransientDetector_fx( TransientDetector *pTransientDetector, Word16 element_mode ) @@ -1557,7 +1486,7 @@ static void RunTransientDetector_fx( assert( ( pTransientDetector->CheckSubblocksForAttack_fx != NULL ) ); #define WMC_TOOL_SKIP -#ifdef HARMONIZE_2508_GetAttackForTCXDecision +#ifdef HARMONIZE_2508_InitTransientDetection pTransientDetector->CheckSubblocksForAttack_fx( pSubblockNrg, pAccSubblockNrg, NSUBBLOCKS + nDelay, nRelativeDelay, attackRatioThreshold, -- GitLab From 0d51d545c7a3213a7f3cea076403679b8338e564 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Mon, 13 Apr 2026 06:01:07 +0000 Subject: [PATCH 10/11] tiny corrections --- lib_enc/transient_detection_fx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 2c32b2d26..ba102064b 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -66,6 +66,7 @@ static void UpdateSubblockEnergies_ivas_fx( Word16 const *input, const Word16 nS /* Functions that define transient detectors */ /* */ /************************************************/ + /** TCX decision. * Check IF there is an attack in a subblock. Version FOR TCX Long/Short decision. * See TCheckSubblocksForAttack_fx FOR definition of parameters. @@ -206,7 +207,7 @@ static void GetAttackForTCXDecision_fx( move16(); bIsAttackPresent = TRUE; #ifdef HARMONIZE_2508_InitTransientDetection - if ( GT_32( element_mode, EVS_MONO ) ) + if ( GT_16( element_mode, EVS_MONO ) ) { attackIndex = 0; move16(); @@ -348,6 +349,7 @@ static void InitTCXTransientDetector( TransientDetector *pTransientDetector ) { InitTransientDetector_fx( pSubblockEnergies, nDelay, NSUBBLOCKS, GetAttackForTCXDecision, 17408 /*8.5f/(1<delayBuffer ); + /* Init a subblock energies buffer used for the TCX Short/Long decision. */ #ifdef HARMONIZE_2508_InitTransientDetection InitSubblockEnergies_fx( nFrameLength, nTCXDelay, &hTranDet->delayBuffer, &hTranDet->subblockEnergies, element_mode ); -- GitLab From 92eac65862a41dcabaf1360d43bf616221437e1b Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 16 Apr 2026 10:18:26 +0200 Subject: [PATCH 11/11] few smaller adjustments --- lib_enc/init_enc_fx.c | 25 ++++++++----------------- lib_enc/transient_detection_fx.c | 8 ++++---- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index ee40a15bc..e47b7621f 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -1200,31 +1200,22 @@ ivas_error init_encoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } -#ifdef HARMONIZE_2508_InitTransientDetection - { - Word16 nTCXDelay = 0; - move16(); - Word16 ext_mem_flag = 1; - move16(); - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - nTCXDelay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - ext_mem_flag = 0; - } - - InitTransientDetection_fx( input_frame, nTCXDelay, st->hTranDet, ext_mem_flag, st->element_mode ); - } -#else IF( GT_16( st->element_mode, EVS_MONO ) ) { +#ifdef HARMONIZE_2508_InitTransientDetection + InitTransientDetection_fx( input_frame, 0, st->hTranDet, 1, 1 /* > EVS_MONO */ ); +#else InitTransientDetection_ivas_fx( input_frame, 0, st->hTranDet, 1 ); +#endif } ELSE { +#ifdef HARMONIZE_2508_InitTransientDetection + InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet, 0, EVS_MONO ); +#else InitTransientDetection_fx( input_frame, NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ), st->hTranDet ); - } #endif + } /*-----------------------------------------------------------------* * IVAS parameters diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index ba102064b..a413e8ac1 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -222,18 +222,18 @@ static void GetAttackForTCXDecision_fx( FOR( i = 0; i < NSUBBLOCKS; i++ ) { #ifdef HARMONIZE_2508_InitTransientDetection - int condition; + Word16 condition; IF( EQ_16( element_mode, EVS_MONO ) ) { L_tmp2 = L_shr( pSubblockNrg[i], ATTACKTHRESHOLD_E ); L_tmp1 = Mpy_32_16_1( pAccSubblockNrg[i], attackRatioThreshold ); - condition = GT_32( L_tmp2, L_tmp1 ); + condition = (Word16) GT_32( L_tmp2, L_tmp1 ); } ELSE { W_tmp2 = W_shr( W_mult_32_16( pAccSubblockNrg[i], attackRatioThreshold ), 1 ); W_tmp1 = W_shl( pSubblockNrg[i], ( 15 - ATTACKTHRESHOLD_E ) ); - condition = GT_64( W_tmp1, W_tmp2 ); + condition = (Word16) GT_64( W_tmp1, W_tmp2 ); } IF( condition ) #else @@ -419,7 +419,7 @@ void InitTransientDetection_ivas_fx( /* We need two past subblocks for the TCX TD and NSUBBLOCKS+1 for the temporal flatness measure FOR the TCX LTP. */ #ifdef HARMONIZE_2508_InitTransientDetection - IF( ext_mem_flag && GT_32( element_mode, EVS_MONO ) ) + IF( ext_mem_flag && GT_16( element_mode, EVS_MONO ) ) { hTranDet->transientDetector.pSubblockEnergies->nDelay = add( hTranDet->transientDetector.pSubblockEnergies->nDelay, add( ( NSUBBLOCKS + 1 ), ( NSUBBLOCKS_SHIFT + 1 ) ) ); -- GitLab