From e514f29549fb9de38ee2df8bb74c8addae7c791d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 17:32:10 +0100 Subject: [PATCH 1/9] HARMONIZE_FUNC --- lib_com/ivas_prot_fx.h | 3 +- lib_com/options.h | 1 + lib_com/prot_fx.h | 37 +++++- lib_com/syn_filt_fx.c | 12 +- lib_dec/TonalComponentDetection_fx.c | 170 ++++++++++++++++++------- lib_dec/acelp_core_dec_fx.c | 4 + lib_dec/amr_wb_dec_fx.c | 4 + lib_dec/core_dec_init_fx.c | 8 ++ lib_dec/core_switching_dec_fx.c | 4 + lib_dec/dec_ace_fx.c | 4 + lib_dec/tonalMDCTconcealment_fx.c | 177 ++++++++++++++++++++------- lib_enc/acelp_core_enc_fx.c | 4 + lib_enc/amr_wb_enc_fx.c | 4 + lib_enc/core_enc_init_fx.c | 10 +- 14 files changed, 343 insertions(+), 99 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4b943135e..cccb9d0ab 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1896,6 +1896,7 @@ Word16 GetPLCModeDecision_ivas_fx( ); #endif // !HARMONIZE_2427_GETPLC +#ifndef HARMONIZE_FUNC void ivas_DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], @@ -1916,7 +1917,7 @@ void ivas_DetectTonalComponents_fx( const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ); - +#endif ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ const Word32 element_brate, /* i : element bitrate */ diff --git a/lib_com/options.h b/lib_com/options.h index 20cc81e20..f9f8aedd4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,6 +98,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define FIX_MDCT_STEREO_ENC_STACK /* VA: basop issue 2428: Move IGF temporary buffers out of the highest stack */ +#define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ba82aae4b..6e282c7d2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2298,6 +2298,7 @@ void E_UTIL_synthesis_fx( const Word16 update, const Word16 m ); +#ifndef HARMONIZE_FUNC void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ @@ -2307,15 +2308,18 @@ void synth_mem_updt2( Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec /* i : flag for decoder indication */ ); - void ivas_synth_mem_updt2_fx( +#else +void synth_mem_updt2_fx( +#endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer */ Word16 mem_syn_r[], /* i/o: synthesis filter memory */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec ); + const Word16 dec /* i : flag for decoder indication */ +); void lerp( const Word16 *f, @@ -5892,6 +5896,27 @@ void concealment_signal_tuning_fx( Word16 *outx_new_fx /*Qoutx_new_fx*/, const Word16 past_core ); +#ifdef HARMONIZE_FUNC +void DetectTonalComponents_fx( + Word16 indexOfTonalPeak[], + Word16 lowerIndex[], + Word16 upperIndex[], + Word16 *pNumIndexes, + const Word32 lastPitchLag, + const Word32 currentPitchLag, + const Word16 lastMDCTSpectrum[], + const Word16 lastMDCTSpectrum_exp, + const Word16 scaleFactors[], + const Word16 scaleFactors_exp[], + const Word16 scaleFactors_max_e, + const Word32 secondLastPowerSpectrum[], + const Word16 secondLastPowerSpectrum_e, + const Word16 nSamples, + const Word16 nSamplesCore, + Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins */ + const PsychoacousticParameters *psychParamsCurrent, + const Word16 element_mode ); +#else void DetectTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], @@ -5929,8 +5954,13 @@ void RefineTonalComponents( const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode ); +#endif +#ifdef HARMONIZE_FUNC +void RefineTonalComponents_fx( +#else void ivas_RefineTonalComponents_fx( +#endif Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], @@ -5949,7 +5979,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ - Word16 element_mode, + const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ); ivas_error PsychoacousticParameters_Init( @@ -10717,7 +10747,6 @@ void UnmapIndex_fx( Word32 *Lag /* Q0 */ ); -// #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) #define GET_ADJ2( T, L, F ) ( sub( shl( L, F ), T ) ) Word32 tcx_hm_render_fx( diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 08d040662..f04688bd7 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -548,14 +548,19 @@ void E_UTIL_synthesis_fx( * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching *--------------------------------------------------------------------*/ +#ifdef HARMONIZE_FUNC +void synth_mem_updt2_fx( +#else void ivas_synth_mem_updt2_fx( +#endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ - const Word16 dec ) + const Word16 dec /* i : flag for decoder indication */ +) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; Word32 en1, en2; @@ -622,7 +627,11 @@ void ivas_synth_mem_updt2_fx( { Copy( mem_syn2, mem_syn, M ); } + + return; } +#ifndef HARMONIZE_FUNC + void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ @@ -660,3 +669,4 @@ void synth_mem_updt2( Copy( mem_syn2, mem_syn, M ); } } +#endif diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index e0fd08107..dac62202e 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -2,8 +2,6 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ -#define _USE_MATH_DEFINES - #include #include #include "options.h" @@ -14,23 +12,35 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ + static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); +#ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); +#endif static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); +#ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); +#endif static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); +#ifdef HARMONIZE_FUNC +static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); +static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); +#else static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void ivas_RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); +#endif + /*-------------------------------------------------------------------* * DetectTonalComponents() @@ -41,7 +51,11 @@ static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lower * pNumIndexes accordingly. *-------------------------------------------------------------------*/ +#ifdef HARMONIZE_FUNC +void DetectTonalComponents_fx( +#else void ivas_DetectTonalComponents_fx( +#endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ @@ -59,7 +73,11 @@ void ivas_DetectTonalComponents_fx( const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ const PsychoacousticParameters *psychParamsCurrent, +#ifdef HARMONIZE_FUNC + const Word16 element_mode /* i : element mode */ +#else Word16 element_mode /* i : element mode */ +#endif ) { Word16 F0; @@ -71,60 +89,80 @@ void ivas_DetectTonalComponents_fx( set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); - FOR( Word16 i = 0; i < nSamples; i++ ) - { - pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ - move32(); - } - FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) - { - sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 - move32(); - } - IF( psychParamsCurrent == NULL ) +#ifdef HARMONIZE_FUNC + IF( element_mode == EVS_MONO ) { - nBands = FDNS_NPTS; - move16(); - mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); + lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); } ELSE +#endif { - q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); - sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore, NULL ); - q_pScaledMdctSpectrum = add( q_pScaledMdctSpectrum, 1 ); - Word16 tmp_e = sub( 31, q_pScaledMdctSpectrum ); - nBands = psychParamsCurrent->nBands; - move16(); - // till nSamplesCore different Q and nSamples - nSamplesCore in different Q - Scale_sig32( pScaledMdctSpectrum + nSamplesCore, sub( nSamples, nSamplesCore ), sub( lastMDCTSpectrum_exp, tmp_e ) ); /*q_pScaledMdctSpectrum+lastMDCTSpectrum_exp-tmp_e*/ - lastMDCTSpect_exp = sub( 31, q_pScaledMdctSpectrum ); - - FOR( Word16 i = nSamplesCore; i < nSamples; ++i ) + FOR( Word16 i = 0; i < nSamples; i++ ) { - Word64 tmp = W_mult_32_32( pScaledMdctSpectrum[i], sns_int_scf_fx[nBands - 1] ); /*q_pScaledMdctSpectrum+16+1*/ - pScaledMdctSpectrum[i] = W_extract_h( W_shl( tmp, Q15 ) ); /*q_pScaledMdctSpectrum*/ + pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ move32(); } - } + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) + { + sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 + move32(); + } + IF( psychParamsCurrent == NULL ) + { + nBands = FDNS_NPTS; + move16(); - /* Guard bit */ - lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); - scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ + mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); + lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); + } + ELSE + { + q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); + sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore, NULL ); + q_pScaledMdctSpectrum = add( q_pScaledMdctSpectrum, 1 ); + Word16 tmp_e = sub( 31, q_pScaledMdctSpectrum ); + nBands = psychParamsCurrent->nBands; + move16(); + // till nSamplesCore different Q and nSamples - nSamplesCore in different Q + Scale_sig32( pScaledMdctSpectrum + nSamplesCore, sub( nSamples, nSamplesCore ), sub( lastMDCTSpectrum_exp, tmp_e ) ); /*q_pScaledMdctSpectrum+lastMDCTSpectrum_exp-tmp_e*/ + lastMDCTSpect_exp = sub( 31, q_pScaledMdctSpectrum ); + + FOR( Word16 i = nSamplesCore; i < nSamples; ++i ) + { + Word64 tmp = W_mult_32_32( pScaledMdctSpectrum[i], sns_int_scf_fx[nBands - 1] ); /*q_pScaledMdctSpectrum+16+1*/ + pScaledMdctSpectrum[i] = W_extract_h( W_shl( tmp, Q15 ) ); /*q_pScaledMdctSpectrum*/ + move32(); + } + } + + /* Guard bit */ + lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); + scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ + } /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ +#ifdef HARMONIZE_FUNC + RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); +#else ivas_RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); +#endif /* Find peaks in the second last frame */ +#ifdef HARMONIZE_FUNC + findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); +#else ivas_findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); +#endif return; } +#ifndef HARMONIZE_FUNC void DetectTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ @@ -162,6 +200,7 @@ void DetectTonalComponents( return; } +#endif /*-------------------------------------------------------------------* * RefineTonalComponents() @@ -173,6 +212,7 @@ void DetectTonalComponents( * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ +#ifndef HARMONIZE_FUNC void RefineTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ @@ -258,8 +298,13 @@ void RefineTonalComponents( return; } +#endif +#ifdef HARMONIZE_FUNC +void RefineTonalComponents_fx( +#else void ivas_RefineTonalComponents_fx( +#endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ @@ -278,7 +323,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ - Word16 element_mode, + const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ) { Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; /*Q0*/ @@ -288,9 +333,15 @@ void ivas_RefineTonalComponents_fx( Word16 iNew, iOld, j; Word16 *pOldPhase, *pNewPhase; +#ifdef HARMONIZE_FUNC + DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, + lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, + psychParamsCurrent, element_mode ); +#else ivas_DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); +#endif nPreservedPeaks = 0; move16(); @@ -561,7 +612,7 @@ static void GetF0( return; } - +#ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 /*short*/ const nSamples, /*i - Q0 */ Word16 /*short*/ const nSamplesCore, /*i - Q0 */ @@ -620,7 +671,7 @@ static void ivas_GetF0_fx( return; } - +#endif static void findStrongestHarmonics( const Word16 nSamples, @@ -703,6 +754,7 @@ static void findStrongestHarmonics( *pnHarmonics = nPeaks; /*Q0*/ move16(); + return; } @@ -853,7 +905,7 @@ static void CorrectF0( return; } - +#ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ @@ -1007,7 +1059,7 @@ static void ivas_CorrectF0_fx( return; } - +#endif static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ @@ -1211,7 +1263,7 @@ static void findCandidates( return; } - +#ifndef HARMONIZE_FUNC static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, @@ -1252,9 +1304,13 @@ static void RefineThresholdsUsingPitch( return; } +#endif - +#ifdef HARMONIZE_FUNC +static void findTonalComponents_fx( +#else static void ivas_findTonalComponents_fx( +#endif Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Word16 *upperIndex, /* OUT Q0*/ @@ -1287,11 +1343,27 @@ static void ivas_findTonalComponents_fx( tmp_loop2 = sub( nSamples, 1 ); WHILE( LE_16( k, tmp_loop1 ) ) { - Word64 mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 - Word16 lshift = W_norm( mult_64 ); - Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 - Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); +#ifdef HARMONIZE_FUNC + Word16 flag = 0; + IF( element_mode == EVS_MONO && GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) + { + flag = 1; + move16(); + } + ELSE + { +#endif + Word64 mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 + Word16 lshift = W_norm( mult_64 ); + Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 + Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); +#ifdef HARMONIZE_FUNC + flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); + } +#else Word16 flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); +#endif + /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ IF( EQ_16( flag, 1 ) ) { @@ -1418,8 +1490,11 @@ static void ivas_findTonalComponents_fx( return; } - +#ifdef HARMONIZE_FUNC +static void RefineThresholdsUsingPitch_fx( +#else static void ivas_RefineThresholdsUsingPitch_fx( +#endif const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], /*Qx*/ @@ -1445,9 +1520,13 @@ static void ivas_RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { +#ifdef HARMONIZE_FUNC + GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); +#else ivas_GetF0_fx( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); +#endif modifyThresholds( *pF0, origF0, thresholdModification ); } @@ -1460,7 +1539,6 @@ static void ivas_RefineThresholdsUsingPitch_fx( return; } - static void findTonalComponents( Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index eefc304e3..11aa13d71 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -448,7 +448,11 @@ ivas_error acelp_core_dec_fx( dec = DEC_IVAS; move16(); } +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); +#else ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); +#endif Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 00347cac7..3a70b49d1 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -278,7 +278,11 @@ ivas_error amr_wb_dec_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); /* update synthesis filter memories */ +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); +#else synth_mem_updt2( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); +#endif Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); /*Q_syn*/ diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index a71fe3d3e..7e18111c8 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -538,7 +538,11 @@ void open_decoder_LPD_fx( IF( !st->last_con_tcx ) { +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#else synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#endif } /*mem of deemphasis stayed unchanged.*/ @@ -1582,7 +1586,11 @@ void open_decoder_LPD_ivas_fx( move16(); IF( !st->last_con_tcx ) { +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#else ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#endif } /*mem of deemphasis stayed unchanged.*/ diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index b8f4cc63f..4e1281954 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1661,7 +1661,11 @@ ivas_error core_switching_pre_dec_fx( ELSE IF( LT_16( st->L_frame, L_FRAME16k ) ) { /* resample from 16kHz to 12.8kHZ */ +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#else synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#endif } IF( hBWE_TD != NULL ) diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index ac137b37c..c78697921 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -174,7 +174,11 @@ void decoder_acelp_fx( test(); IF( st->prev_bfi && st->last_con_tcx && LT_16( st->L_frame, L_FRAME16k ) ) { +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#else synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#endif } test(); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0a8892dba..0535c5d86 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -21,7 +21,11 @@ static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, const Word16 *timeSignal, Word32 *mdxtOutput, Word16 *mdxtOutput_e ); static void CalcPowerSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word32 *mdstSpec, const Word16 mdstSpec_exp, const Word16 nSamples, const Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); +#ifdef HARMONIZE_FUNC +static void CalcPowerSpecAndDetectTonalComponents_fx( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ); +#else static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], Word16 secondLastMDST_exp, Word32 secondLastMDCT[], Word16 secondLastMDCT_exp, Word32 const pitchLag, Word16 element_mode ); +#endif static void FindPhases( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp ); static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[] ); @@ -216,6 +220,8 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( return IVAS_ERR_OK; } + + void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr hTonalMDCTConc, const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp @@ -702,9 +708,15 @@ static void FindPhaseDifferences( } } } + + return; } +#ifdef HARMONIZE_FUNC +static void CalcPowerSpecAndDetectTonalComponents_fx( +#else static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( +#endif TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], // Q31 - secondLastMDST_exp Word16 secondLastMDST_exp, @@ -732,7 +744,16 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); /* It is taken into account that the MDCT is not normalized. */ - floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_32( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 5368709 ) ); /*1/400 = 5368709 Q31*/ +#ifdef HARMONIZE_FUNC + IF( element_mode == EVS_MONO ) + { + floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ); /*1/400 = 82 Q15*/ + } + ELSE +#endif + { + floorPowerSpectrum /*Q0*/ = extract_l( Mpy_32_32( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 5368709 ) ); /*1/400 = 5368709 Q31*/ + } powerSpectrum_exp = 0; move16(); @@ -756,6 +777,24 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); } +#ifdef HARMONIZE_FUNC + DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + hTonalMDCTConc->lastBlockData.spectralData_exp, + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + powerSpectrum_exp, + nSamples, + hTonalMDCTConc->nSamplesCore, + floorPowerSpectrum, psychParamsCurrent, element_mode ); +#else ivas_DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -772,6 +811,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); +#endif + FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); @@ -807,6 +848,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( move16(); Word16 length = 0; move16(); + /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ IF( psychParamsCurrent == NULL ) { @@ -826,26 +868,42 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( nBands = psychParamsCurrent->nBands; move16(); } - IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) - { - Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) - } - ELSE + +#ifdef HARMONIZE_FUNC + IF( element_mode != EVS_MONO ) +#endif { - Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); // Q(power_spectrum_q - old_power_spectrum_q) - powerSpectrum_exp = sub( 31, power_spectrum_q ); + IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) + { + Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) + } + ELSE + { + Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); // Q(power_spectrum_q - old_power_spectrum_q) + powerSpectrum_exp = sub( 31, power_spectrum_q ); + } + Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 + powerSpectrum_exp = add( powerSpectrum_exp, 3 ); } - Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 - powerSpectrum_exp = add( powerSpectrum_exp, 3 ); + FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); // Q(31 - powerSpectrum_exp) move32(); } - Word16 shift = Find_Max_Norm32( powerSpectrum, nSamples ); - scale_sig32( powerSpectrum, nSamples, shift ); - powerSpectrum_exp = sub( powerSpectrum_exp, shift ); +#ifdef HARMONIZE_FUNC + IF( element_mode == EVS_MONO ) + { + powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); + } + ELSE +#endif + { + Word16 shift = Find_Max_Norm32( powerSpectrum, nSamples ); + scale_sig32( powerSpectrum, nSamples, shift ); + powerSpectrum_exp = sub( powerSpectrum_exp, shift ); + } /* 16 bits are now enough for storing the power spectrum */ FOR( i = 0; i < nSamples; i++ ) @@ -857,8 +915,11 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc->secondLastPowerSpectrum_exp = powerSpectrum_exp; move16(); } + + return; } +#ifndef HARMONIZE_FUNC static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDST[], // Q31-secondLastMDST_exp @@ -920,6 +981,7 @@ static void CalcPowerSpecAndDetectTonalComponents( nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, element_mode ); + FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); @@ -973,7 +1035,7 @@ static void CalcPowerSpecAndDetectTonalComponents( move16(); } } - +#endif static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, @@ -1073,7 +1135,11 @@ void TonalMDCTConceal_Detect( } secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); +#ifdef HARMONIZE_FUNC + CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, NULL, element_mode ); +#else CalcPowerSpecAndDetectTonalComponents( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, element_mode ); +#endif } ELSE { @@ -1097,23 +1163,34 @@ void TonalMDCTConceal_Detect( move32(); } +#ifdef HARMONIZE_FUNC + RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, +#else RefineTonalComponents( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *) hTonalMDCTConc->pTCI->upperIndex, - hTonalMDCTConc->pTCI->phaseDiff, - hTonalMDCTConc->pTCI->phase_currentFramePredicted, - (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - nSamples, - hTonalMDCTConc->nSamplesCore, +#endif + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, +#ifdef HARMONIZE_FUNC + -1, +#endif + nSamples, + hTonalMDCTConc->nSamplesCore, +#ifdef HARMONIZE_FUNC + extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, NULL ); +#else extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode ); /* floorPowerSpectrum */ +#endif } } } @@ -1204,7 +1281,11 @@ void TonalMDCTConceal_Detect_ivas_fx( } secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); +#ifdef HARMONIZE_FUNC + CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); +#else ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); +#endif } ELSE { @@ -1253,24 +1334,28 @@ void TonalMDCTConceal_Detect_ivas_fx( powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } +#ifdef HARMONIZE_FUNC + RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, +#else ivas_RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, - (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, - (Word16 *) hTonalMDCTConc->pTCI->upperIndex, - hTonalMDCTConc->pTCI->phaseDiff, - hTonalMDCTConc->pTCI->phase_currentFramePredicted, - (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, - hTonalMDCTConc->lastPitchLag, - pitchLag, - hTonalMDCTConc->lastBlockData.spectralData, - add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), - hTonalMDCTConc->lastBlockData.scaleFactors, - hTonalMDCTConc->lastBlockData.scaleFactors_exp, - hTonalMDCTConc->lastBlockData.scaleFactors_max_e, - powerSpectrum, - powerSpectrum_exp, - nSamples, - hTonalMDCTConc->nSamplesCore, - extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ +#endif + (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, + (Word16 *) hTonalMDCTConc->pTCI->upperIndex, + hTonalMDCTConc->pTCI->phaseDiff, + hTonalMDCTConc->pTCI->phase_currentFramePredicted, + (Word16 *) &hTonalMDCTConc->pTCI->numIndexes, + hTonalMDCTConc->lastPitchLag, + pitchLag, + hTonalMDCTConc->lastBlockData.spectralData, + add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ), + hTonalMDCTConc->lastBlockData.scaleFactors, + hTonalMDCTConc->lastBlockData.scaleFactors_exp, + hTonalMDCTConc->lastBlockData.scaleFactors_max_e, + powerSpectrum, + powerSpectrum_exp, + nSamples, + hTonalMDCTConc->nSamplesCore, + extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ } } } diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 2168e0e3a..7a7b4ef59 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -309,7 +309,11 @@ ivas_error acelp_core_enc_fx( set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#else synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#endif Copy( hLPDmem->old_exc, old_exc_fx, L_EXC_MEM ); // Q_new Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn1_fx, M ); /* hLPDmem->q_mem_syn */ Copy( hLPDmem->mem_syn2, hLPDmem->mem_syn3, M ); /* hLPDmem->q_mem_syn */ diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 5f14a9b66..ca617fec2 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -207,7 +207,11 @@ void amr_wb_enc_fx( set16_fx( st->mem_MA_fx, 0, M ); /* update synthesis filter memories */ +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC ); +#else synth_mem_updt2( L_FRAME, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn1_fx, hLPDmem->mem_syn, ENC ); +#endif Copy( hLPDmem->mem_syn1_fx, hLPDmem->mem_syn2, M ); /* q_mem_syn */ Copy( hLPDmem->old_exc, old_exc, L_EXC_MEM ); /* q_lpd_old_exc */ diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index 85c945f9c..d34f08d95 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -717,7 +717,11 @@ static void init_acelp_fx( Encoder_State *st, Word16 L_frame_old, const Word16 s Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#else synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#endif /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ { @@ -1698,7 +1702,11 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh /*Mem of deemphasis stay unchanged : hLPDmem->syn*/ IF( hLPDmem != NULL ) { - synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#ifdef HARMONIZE_FUNC + synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#else + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC ); +#endif Word16 tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1]; /* Update wsyn */ /* lsp2a_stab( st->lsp_old, A, M ); */ -- GitLab From a0df0ffb4d0c24b4bb31de4be4d892b3594142f8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 17:37:26 +0100 Subject: [PATCH 2/9] fix warning --- lib_dec/TonalComponentDetection_fx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index dac62202e..8e92f4670 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -1538,6 +1538,7 @@ static void ivas_RefineThresholdsUsingPitch_fx( return; } +#ifndef HARMONIZE_FUNC static void findTonalComponents( Word16 *indexOfTonalPeak, /* OUT Q0*/ @@ -1696,3 +1697,4 @@ static void findTonalComponents( return; } +#endif -- GitLab From 70490df67c77fbaa8ebbf6769b067d83f0feb8bc Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 18:15:23 +0100 Subject: [PATCH 3/9] formatting in vad_fx.c --- lib_enc/pit_enc_fx.c | 8 +++ lib_enc/prot_fx_enc.h | 3 +- lib_enc/vad_fx.c | 133 ++++++++++++++++-------------------------- 3 files changed, 60 insertions(+), 84 deletions(-) diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index 1fff57905..f39756da3 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -17,6 +17,10 @@ #define inv_T0_res InvIntTable static void limit_T0_voiced2( Word16 res, const Word16 *T_op, Word16 *T0_min, Word16 *T0_min_frac, Word16 *T0_max, Word16 *T0_max_frac, Word16 pit_min, Word16 pit_max, Word16 i_subfr ); +#ifdef HARMONIZE_FUNC +static void norm_corr_ivas_fx( const Word16 exc[], const Word16 xn[], const Word16 h[], const Word16 t_min, const Word16 t_max, Word16 ncorr[], const Word16 L_subfr, Word16 Q_new ); +#endif + /*==============================================================================*/ /* FUNCTION : pit_encode_fx() */ @@ -951,7 +955,11 @@ Word16 pitch_fr4_fx( * excitation) *---------------------------------------------------------------------*/ +#ifdef HARMONIZE_FUNC +static void norm_corr_ivas_fx( +#else void norm_corr_ivas_fx( +#endif const Word16 exc[], /* i : excitation buffer Q_new */ const Word16 xn[], /* i : target signal Q_new-1 */ const Word16 h[], /* i : weighted synthesis filter impulse response Q(14 - norm_s(h[0])) */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 153c24b36..25c99057a 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -831,6 +831,7 @@ void norm_corr_fx( const Word16 L_subfr /* i : subframe size */ ); +#ifndef HARMONIZE_FUNC void norm_corr_ivas_fx( const Word16 exc[], /* i : excitation buffer Q_new */ const Word16 xn[], /* i : target signal Q_new-1 */ @@ -841,7 +842,7 @@ void norm_corr_ivas_fx( const Word16 L_subfr, /* i : subframe size */ Word16 Q_new /* i */ ); - +#endif Word16 peak_avrg_ratio_fx( const Word32 total_brate, /* Q0 */ const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index eec0b656d..c8d2a5659 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -13,17 +13,13 @@ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -/* old fx constants */ -#define HANGOVER_LONG 10 /* Hangover for CNG */ -#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ -#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ -#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ /* SNR threshold curve constants for WB input */ #define SK16_2_FX 16930 /* Q14 (1.0333f)-> Linear function for clean speech */ #define SC16_2_FX -4608 /* Q8 (-18)*/ #define NK16_2_FX 13529 /* Q15 (.41287)-> Linear function for noisy speech */ #define NC16_2_FX 3394 /* Q8 (13.259625)*/ + /* SNR threshold curve constants for NB input */ #define NK8_1_FX 3509 /*Q15 (0.1071f) Linear function for noisy speech */ #define NC8_1_FX 4224 /*Q8 (16.5f) */ @@ -32,14 +28,12 @@ #define SIGN_THR_FX 40 /*Q4 (2.5f) Significanse threshold for per band snr calculation */ #define MIN_SNR_FX 2 /*Q4 Minimum snr used for per band snr calculation */ - #define THR_M0_FX 3379 /* Q8 (13.2) Zero ofset for threshod */ #define THR_K_BG_FX -8192 /* Q15(-0.25) Coefficient for dependence on background level */ #define THR_K_BG_OFS_FX 5120 /* Q8 (20.0f) Zero offset for background level */ #define THR_K_SNR_FX 3277 /* Q15 (0.1f) Coefficient for dependence on SNR */ #define THR_K_EV_FX 18022 /* Q15 (0.55) Coefficient for dependence on noise variations */ - #define HO_DTX_CLEAN 1 /* Hangover for dtx in clean conditions */ #define HO_DTX_NOISY 10 /* Hangover for dtx in noisy conditions */ #define HO_DTX_NOISY2 4 /* Hangover for dtx in very noisy conditions */ @@ -47,7 +41,6 @@ #define ONE_LG10 2466 /* 1.0*log10(2) in Q13 */ - #define HANGOVER_LONG_FX 10 /* Hangover for CNG */ #define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */ #define HANGOVER_LONG_HE_FX 20 /* Hangover of CNG */ @@ -61,7 +54,6 @@ #define TH16_2_NFLAG_FX 8960 /* Q8 (35) */ #define TH8_1_NFLAG_FX 8960 /* Q8 (35) */ - #define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14 (1.00)*/ #define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14 (1.01)*/ #define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14 (1.02)*/ @@ -74,7 +66,12 @@ #define MAX_SNR_OUTLIER_3_FX 800 /*Q4 (50.0f)*/ -/* snr_sum = "scale" * (float)log10( L_snr_sum ) ;*/ +/*-----------------------------------------------------------------* + * vad_snr_log_fx() + * + * snr_sum = "scale" * (float)log10( L_snr_sum ) ; + *-----------------------------------------------------------------*/ + /* o: Q8 */ static Word16 vad_snr_log_fx( Word32 L_snr, /* i : Q4 */ @@ -88,6 +85,7 @@ static Word16 vad_snr_log_fx( f_snr = Log2_norm_lc( L_shl( L_snr, e_snr ) ); e_snr = sub( 30 - 4, e_snr ); L_tmp = Mpy_32_16( e_snr, f_snr, scale ); + return round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ } @@ -169,14 +167,17 @@ void wb_vad_init_fx( move16(); hVAD->hangover_terminate_flag = 0; move16(); + return; } + /*-----------------------------------------------------------------* * sign_thr_snr_acc_fx() * * accumulate snr_sum with significance thresholds *-----------------------------------------------------------------*/ + static void sign_thr_snr_acc_ivas_fx( Word32 *L_snr_sum, /* o : q_snr_sum */ Word16 *q_snr_sum, @@ -199,8 +200,11 @@ static void sign_thr_snr_acc_ivas_fx( *q_snr_sum = sub( 31, exp_snr_sum ); move32(); move32(); + + return; } + static void sign_thr_snr_acc_fx( Word32 *L_snr_sum, /* o : Q4 */ Word32 L_snr, /* i : Q4 */ @@ -221,8 +225,11 @@ static void sign_thr_snr_acc_fx( /* Q4 */ move32(); BASOP_SATURATE_WARNING_ON_EVS + + return; } + /*-----------------------------------------------------------------* * dtx_hangover_addition_fx() * @@ -447,19 +454,19 @@ Word16 dtx_hangover_addition_fx( * * Voice Activity Detector *-----------------------------------------------------------------*/ -/* new simplified and harmonized code */ + Word16 wb_vad_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16 *localVAD_HE_SAD, - Word16 *flag_noisy_speech_snr, /* o : */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, /* o : HE-SAD flag without hangover */ + Word16 *flag_noisy_speech_snr, /* o : encoder detector for noisy speech */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) @@ -500,7 +507,6 @@ Word16 wb_vad_fx( Word16 snr_sum_HE_SAD; /*Q8 log */ Word16 sign_thr_HE_SAD, min_snr_HE_SAD; - Word16 thr1_ol; Word32 L_snr_sum_ol; Word16 snr_sum_ol; /* Q8 log */ @@ -572,11 +578,12 @@ Word16 wb_vad_fx( last_7k2_coder_type = -1; move16(); } + /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ - IF( EQ_16( st_fx->max_band, 19 ) ) - /* WB input */ /* or SWB input */ + + IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */ { nk = 3277; move16(); /*0.1 Q15 */ @@ -606,10 +613,8 @@ Word16 wb_vad_fx( sign_thr_HE_SAD = 40; move16(); /* 2.5f Q4 */ - ; min_snr_HE_SAD = 3; move16(); /* 0.2f Q4 */ - ; } ELSE /* NB input */ { @@ -630,23 +635,19 @@ Word16 wb_vad_fx( move16(); /* .25 *Q4 MIN_SNR */ sign_thr_HE_SAD = 42; move16(); /* 2.65f Q4 */ - ; min_snr_HE_SAD = 1; move16(); /* 0.05f Q4 */ - ; } hangover_short = 0; move16(); - /* IF( st_fx->Opt_SC_VBR != 0 ) */ *noisy_speech_HO = 0; move16(); *clean_speech_HO = 0; move16(); *NB_speech_HO = 0; move16(); - /* } */ /*---------------------------------------------------------------------* * compute SNR for each band & total @@ -667,7 +668,6 @@ Word16 wb_vad_fx( move16(); } - IF( snr_idx == 0 ) { stmp = 6; @@ -681,7 +681,6 @@ Word16 wb_vad_fx( delta4 = 0; move16(); - /*vad_thr = 2.4f*lp_snr - 42.2f; vad_thr = min(vad_thr, 80 ); */ @@ -749,7 +748,6 @@ Word16 wb_vad_fx( snr_sum_HE_SAD = 0; move16(); - FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) { ftmp = L_add( *pt1++, 0 ); @@ -835,14 +833,12 @@ Word16 wb_vad_fx( } L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ - /* snr[i] = (float)log10(snr[i]); */ snr = vad_snr_log_fx( L_snr, ONE_LG10 ); /* snr_sumt += snr[i];*/ snr_sumt = add( snr_sumt, shr( snr, 4 ) ); /*Q4 */ - tmp = shl_sat( snr, 5 ); /* Q8 -> Q13 */ IF( LT_16( i, 2 ) ) { @@ -929,7 +925,6 @@ Word16 wb_vad_fx( L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/ } - /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ sign_thr_snr_acc_fx( &L_snr_sum_HE_SAD, L_snr, sign_thr_HE_SAD, min_snr_HE_SAD ); sign_thr_snr_acc_fx( &L_snr_sum, L_snr, sign_thr, min_snr ); @@ -992,7 +987,6 @@ Word16 wb_vad_fx( } } - /* Separated SNR_SUM outlier modification */ L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ @@ -1003,7 +997,6 @@ Word16 wb_vad_fx( { /* Update the total SNR only for WB signals */ - /* corresponding float section if( (accum_ener_L > OUTLIER_THR_1 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_1) ) { @@ -1023,7 +1016,6 @@ Word16 wb_vad_fx( test(); IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) ) - { /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */ @@ -1062,10 +1054,10 @@ Word16 wb_vad_fx( *snr_sum_he = snr_sum_HE_SAD; move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ - /*---------------------------------------------------------------------* * compute thr1 for SAD decision *---------------------------------------------------------------------*/ + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ sub( 0, 0 ); @@ -1103,7 +1095,6 @@ Word16 wb_vad_fx( } } - /*---------------------------------------------------------------------* * WB input * SNR threshold computing @@ -1112,7 +1103,6 @@ Word16 wb_vad_fx( IF( NE_16( vad_bwidth_fx, NB ) ) { - /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of modyfying thr1 and snr_sum */ @@ -1215,7 +1205,6 @@ Word16 wb_vad_fx( move16(); } - IF( GT_16( hVAD->voiced_burst, 3 ) ) { IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ @@ -1230,14 +1219,12 @@ Word16 wb_vad_fx( } } - hangover_hd = hangover_hd_tbl[snr_idx]; move16(); IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) { hangover_hd = add( shr( hangover_hd, 1 ), 1 ); - // move16(); } /* VAD hangover for he1 */ @@ -1274,7 +1261,6 @@ Word16 wb_vad_fx( move16(); } - /* Calculate background stationarity */ test(); IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) @@ -1419,7 +1405,6 @@ Word16 wb_vad_fx( } } - /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ *localVAD_HE_SAD = 0; @@ -1492,7 +1477,6 @@ Word16 wb_vad_fx( } } - thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ /* -dtx condition dependency in noisy speech */ @@ -1508,7 +1492,6 @@ Word16 wb_vad_fx( thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } - flag = 0; move16(); if ( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ @@ -1517,7 +1500,6 @@ Word16 wb_vad_fx( move16(); } - test(); IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ { @@ -1536,7 +1518,6 @@ Word16 wb_vad_fx( move16(); /* needed for st_fx->vadnoise_fx update below */ } /* end of NB */ - /* *flag_noisy_speech_snr is a Word8 parameter */ *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); @@ -1647,7 +1628,6 @@ Word16 wb_vad_fx( move16(); } - IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); @@ -1668,19 +1648,19 @@ Word16 wb_vad_fx( } Word16 wb_vad_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ - const Word16 q_fr_bands, /* i : Q of fr_bands */ - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16 *localVAD_HE_SAD, - Word16 *flag_noisy_speech_snr, /* o : */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ - Word16 lp_noise_fx /* i : long term noise energy Q8 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ + const Word16 q_fr_bands, /* i : Q of fr_bands */ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, /* o : HE-SAD flag without hangover */ + Word16 *flag_noisy_speech_snr, /* o : encoder detector for noisy speech */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ + Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) { Word16 i, flag = 0, hangover_short; @@ -1807,11 +1787,12 @@ Word16 wb_vad_ivas_fx( last_7k2_coder_type = -1; move16(); } + /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ - IF( EQ_16( st_fx->max_band, 19 ) ) - /* WB input */ /* or SWB input */ + + IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */ { nk = 3277; move16(); /*0.1 Q15 */ @@ -1846,7 +1827,6 @@ Word16 wb_vad_ivas_fx( } ELSE /* NB input */ { - // move16(); nk = 3277; move16(); /* 0.1 Q15 */ nc = 268435456; @@ -1899,7 +1879,6 @@ Word16 wb_vad_ivas_fx( move16(); } - IF( snr_idx == 0 ) { stmp = 6; @@ -1913,7 +1892,6 @@ Word16 wb_vad_ivas_fx( delta4 = 0; move32(); /*0.0f in Q16 */ - /*vad_thr = 2.4f*lp_snr - 42.2f; vad_thr = min(vad_thr, 80 ); */ @@ -2271,7 +2249,6 @@ Word16 wb_vad_ivas_fx( test(); IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ || LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_1_FX ) ) - { /* snr_sum_ol = SNR_OUTLIER_WGHT_1 * ( snr_sum_ol - snr_outlier ); As SNR_OUTLIER_WGHT_1 is 1.0f we do not need to multiply here , i.e. no need to loose any precisison */ @@ -2318,10 +2295,10 @@ Word16 wb_vad_ivas_fx( *snr_sum_he = snr_sum_HE_SAD; move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ - /*---------------------------------------------------------------------* * compute thr1 for SAD decision *---------------------------------------------------------------------*/ + lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) @@ -2369,7 +2346,6 @@ Word16 wb_vad_ivas_fx( } } - /*---------------------------------------------------------------------* * WB input * SNR threshold computing @@ -2378,7 +2354,6 @@ Word16 wb_vad_ivas_fx( IF( vad_bwidth_fx != NB ) { - /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of modyfying thr1 and snr_sum */ @@ -2490,7 +2465,6 @@ Word16 wb_vad_ivas_fx( move16(); } - IF( GT_16( hVAD->voiced_burst, 3 ) ) { IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ @@ -2505,7 +2479,6 @@ Word16 wb_vad_ivas_fx( } } - hangover_hd = hangover_hd_tbl[snr_idx]; move16(); @@ -2548,7 +2521,6 @@ Word16 wb_vad_ivas_fx( move16(); } - /* Calculate background stationarity */ test(); IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) @@ -2767,7 +2739,6 @@ Word16 wb_vad_ivas_fx( } } - thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ /* -dtx condition dependency in noisy speech */ @@ -2783,7 +2754,6 @@ Word16 wb_vad_ivas_fx( thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } - flag = 0; move16(); IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ @@ -2792,7 +2762,6 @@ Word16 wb_vad_ivas_fx( move16(); } - test(); IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ { @@ -2811,7 +2780,6 @@ Word16 wb_vad_ivas_fx( move16(); /* needed for st_fx->vadnoise_fx update below */ } /* end of NB */ - /* *flag_noisy_speech_snr is a Word8 parameter */ *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); @@ -2923,7 +2891,6 @@ Word16 wb_vad_ivas_fx( move16(); } - IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); /*Q0*/ -- GitLab From d2568c7726054bb2dccc584e474f8d93b6d75532 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 20:08:45 +0100 Subject: [PATCH 4/9] - Revert "formatting in vad_fx.c" --- lib_enc/vad_fx.c | 133 +++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 50 deletions(-) diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index c8d2a5659..eec0b656d 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -13,13 +13,17 @@ /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ +/* old fx constants */ +#define HANGOVER_LONG 10 /* Hangover for CNG */ +#define HANGOVER_LONG_HE 20 /* Hangover of CNG */ +#define HANGOVER_LONG_NB 8 /* Hangover for CNG */ +#define ACTIVE_FRAMES 3 /* Number of consecutive active SPEECH frames necessary to trigger HO */ /* SNR threshold curve constants for WB input */ #define SK16_2_FX 16930 /* Q14 (1.0333f)-> Linear function for clean speech */ #define SC16_2_FX -4608 /* Q8 (-18)*/ #define NK16_2_FX 13529 /* Q15 (.41287)-> Linear function for noisy speech */ #define NC16_2_FX 3394 /* Q8 (13.259625)*/ - /* SNR threshold curve constants for NB input */ #define NK8_1_FX 3509 /*Q15 (0.1071f) Linear function for noisy speech */ #define NC8_1_FX 4224 /*Q8 (16.5f) */ @@ -28,12 +32,14 @@ #define SIGN_THR_FX 40 /*Q4 (2.5f) Significanse threshold for per band snr calculation */ #define MIN_SNR_FX 2 /*Q4 Minimum snr used for per band snr calculation */ + #define THR_M0_FX 3379 /* Q8 (13.2) Zero ofset for threshod */ #define THR_K_BG_FX -8192 /* Q15(-0.25) Coefficient for dependence on background level */ #define THR_K_BG_OFS_FX 5120 /* Q8 (20.0f) Zero offset for background level */ #define THR_K_SNR_FX 3277 /* Q15 (0.1f) Coefficient for dependence on SNR */ #define THR_K_EV_FX 18022 /* Q15 (0.55) Coefficient for dependence on noise variations */ + #define HO_DTX_CLEAN 1 /* Hangover for dtx in clean conditions */ #define HO_DTX_NOISY 10 /* Hangover for dtx in noisy conditions */ #define HO_DTX_NOISY2 4 /* Hangover for dtx in very noisy conditions */ @@ -41,6 +47,7 @@ #define ONE_LG10 2466 /* 1.0*log10(2) in Q13 */ + #define HANGOVER_LONG_FX 10 /* Hangover for CNG */ #define HANGOVER_LONG_MUSIC_FX 20 /* Hangover of CNG */ #define HANGOVER_LONG_HE_FX 20 /* Hangover of CNG */ @@ -54,6 +61,7 @@ #define TH16_2_NFLAG_FX 8960 /* Q8 (35) */ #define TH8_1_NFLAG_FX 8960 /* Q8 (35) */ + #define SNR_OUTLIER_WGHT_1_FX 16384 /* Q14 (1.00)*/ #define SNR_OUTLIER_WGHT_2_FX 16548 /* Q14 (1.01)*/ #define SNR_OUTLIER_WGHT_3_FX 16712 /* Q14 (1.02)*/ @@ -66,12 +74,7 @@ #define MAX_SNR_OUTLIER_3_FX 800 /*Q4 (50.0f)*/ -/*-----------------------------------------------------------------* - * vad_snr_log_fx() - * - * snr_sum = "scale" * (float)log10( L_snr_sum ) ; - *-----------------------------------------------------------------*/ - +/* snr_sum = "scale" * (float)log10( L_snr_sum ) ;*/ /* o: Q8 */ static Word16 vad_snr_log_fx( Word32 L_snr, /* i : Q4 */ @@ -85,7 +88,6 @@ static Word16 vad_snr_log_fx( f_snr = Log2_norm_lc( L_shl( L_snr, e_snr ) ); e_snr = sub( 30 - 4, e_snr ); L_tmp = Mpy_32_16( e_snr, f_snr, scale ); - return round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ } @@ -167,17 +169,14 @@ void wb_vad_init_fx( move16(); hVAD->hangover_terminate_flag = 0; move16(); - return; } - /*-----------------------------------------------------------------* * sign_thr_snr_acc_fx() * * accumulate snr_sum with significance thresholds *-----------------------------------------------------------------*/ - static void sign_thr_snr_acc_ivas_fx( Word32 *L_snr_sum, /* o : q_snr_sum */ Word16 *q_snr_sum, @@ -200,11 +199,8 @@ static void sign_thr_snr_acc_ivas_fx( *q_snr_sum = sub( 31, exp_snr_sum ); move32(); move32(); - - return; } - static void sign_thr_snr_acc_fx( Word32 *L_snr_sum, /* o : Q4 */ Word32 L_snr, /* i : Q4 */ @@ -225,11 +221,8 @@ static void sign_thr_snr_acc_fx( /* Q4 */ move32(); BASOP_SATURATE_WARNING_ON_EVS - - return; } - /*-----------------------------------------------------------------* * dtx_hangover_addition_fx() * @@ -454,19 +447,19 @@ Word16 dtx_hangover_addition_fx( * * Voice Activity Detector *-----------------------------------------------------------------*/ - +/* new simplified and harmonized code */ Word16 wb_vad_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16 *localVAD_HE_SAD, /* o : HE-SAD flag without hangover */ - Word16 *flag_noisy_speech_snr, /* o : encoder detector for noisy speech */ - const Word16 Q_new, /* i : scaling factor Q0 */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band input energy (contains 2 vectors) Q_new+QSCALE*/ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, + Word16 *flag_noisy_speech_snr, /* o : */ + const Word16 Q_new, /* i : scaling factor Q0 */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) @@ -507,6 +500,7 @@ Word16 wb_vad_fx( Word16 snr_sum_HE_SAD; /*Q8 log */ Word16 sign_thr_HE_SAD, min_snr_HE_SAD; + Word16 thr1_ol; Word32 L_snr_sum_ol; Word16 snr_sum_ol; /* Q8 log */ @@ -578,12 +572,11 @@ Word16 wb_vad_fx( last_7k2_coder_type = -1; move16(); } - /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ - - IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */ + IF( EQ_16( st_fx->max_band, 19 ) ) + /* WB input */ /* or SWB input */ { nk = 3277; move16(); /*0.1 Q15 */ @@ -613,8 +606,10 @@ Word16 wb_vad_fx( sign_thr_HE_SAD = 40; move16(); /* 2.5f Q4 */ + ; min_snr_HE_SAD = 3; move16(); /* 0.2f Q4 */ + ; } ELSE /* NB input */ { @@ -635,19 +630,23 @@ Word16 wb_vad_fx( move16(); /* .25 *Q4 MIN_SNR */ sign_thr_HE_SAD = 42; move16(); /* 2.65f Q4 */ + ; min_snr_HE_SAD = 1; move16(); /* 0.05f Q4 */ + ; } hangover_short = 0; move16(); + /* IF( st_fx->Opt_SC_VBR != 0 ) */ *noisy_speech_HO = 0; move16(); *clean_speech_HO = 0; move16(); *NB_speech_HO = 0; move16(); + /* } */ /*---------------------------------------------------------------------* * compute SNR for each band & total @@ -668,6 +667,7 @@ Word16 wb_vad_fx( move16(); } + IF( snr_idx == 0 ) { stmp = 6; @@ -681,6 +681,7 @@ Word16 wb_vad_fx( delta4 = 0; move16(); + /*vad_thr = 2.4f*lp_snr - 42.2f; vad_thr = min(vad_thr, 80 ); */ @@ -748,6 +749,7 @@ Word16 wb_vad_fx( snr_sum_HE_SAD = 0; move16(); + FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) { ftmp = L_add( *pt1++, 0 ); @@ -833,12 +835,14 @@ Word16 wb_vad_fx( } L_snr = L_max( L_snr, 1 * ( 1 << 4 ) ); /* if ( snr[i] < 1 ){snr[i] = 1;}*/ + /* snr[i] = (float)log10(snr[i]); */ snr = vad_snr_log_fx( L_snr, ONE_LG10 ); /* snr_sumt += snr[i];*/ snr_sumt = add( snr_sumt, shr( snr, 4 ) ); /*Q4 */ + tmp = shl_sat( snr, 5 ); /* Q8 -> Q13 */ IF( LT_16( i, 2 ) ) { @@ -925,6 +929,7 @@ Word16 wb_vad_fx( L_snr = L_shr( snr_tmp, shift_snr ); /*L_snr in Q4*/ } + /* conditional snrsum, snr_sum = snr_sum + snr[i];*/ sign_thr_snr_acc_fx( &L_snr_sum_HE_SAD, L_snr, sign_thr_HE_SAD, min_snr_HE_SAD ); sign_thr_snr_acc_fx( &L_snr_sum, L_snr, sign_thr, min_snr ); @@ -987,6 +992,7 @@ Word16 wb_vad_fx( } } + /* Separated SNR_SUM outlier modification */ L_snr_sum_ol = L_snr_sum; /* snr_sum_ol = snr_sum; */ @@ -997,6 +1003,7 @@ Word16 wb_vad_fx( { /* Update the total SNR only for WB signals */ + /* corresponding float section if( (accum_ener_L > OUTLIER_THR_1 * accum_ener_H ) || (snr_outlier < MAX_SNR_OUTLIER_1) ) { @@ -1016,6 +1023,7 @@ Word16 wb_vad_fx( test(); IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ || LT_32( L_snr_outlier, MAX_SNR_OUTLIER_1_FX ) ) + { /* as weight1 is 1.0 we do not need to multiply here , i.e. no need to loose any precisison */ L_snr_sum_ol = L_sub( L_snr_sum_ol, L_snr_outlier ); /*Q4 */ @@ -1054,10 +1062,10 @@ Word16 wb_vad_fx( *snr_sum_he = snr_sum_HE_SAD; move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ + /*---------------------------------------------------------------------* * compute thr1 for SAD decision *---------------------------------------------------------------------*/ - lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ sub( 0, 0 ); @@ -1095,6 +1103,7 @@ Word16 wb_vad_fx( } } + /*---------------------------------------------------------------------* * WB input * SNR threshold computing @@ -1103,6 +1112,7 @@ Word16 wb_vad_fx( IF( NE_16( vad_bwidth_fx, NB ) ) { + /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of modyfying thr1 and snr_sum */ @@ -1205,6 +1215,7 @@ Word16 wb_vad_fx( move16(); } + IF( GT_16( hVAD->voiced_burst, 3 ) ) { IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ @@ -1219,12 +1230,14 @@ Word16 wb_vad_fx( } } + hangover_hd = hangover_hd_tbl[snr_idx]; move16(); IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) { hangover_hd = add( shr( hangover_hd, 1 ), 1 ); + // move16(); } /* VAD hangover for he1 */ @@ -1261,6 +1274,7 @@ Word16 wb_vad_fx( move16(); } + /* Calculate background stationarity */ test(); IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) @@ -1405,6 +1419,7 @@ Word16 wb_vad_fx( } } + /* localVAD and vad_flag for HE-SAD - in parallel with normal localVAD and vad_flag */ *localVAD_HE_SAD = 0; @@ -1477,6 +1492,7 @@ Word16 wb_vad_fx( } } + thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ /* -dtx condition dependency in noisy speech */ @@ -1492,6 +1508,7 @@ Word16 wb_vad_fx( thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } + flag = 0; move16(); if ( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ @@ -1500,6 +1517,7 @@ Word16 wb_vad_fx( move16(); } + test(); IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ { @@ -1518,6 +1536,7 @@ Word16 wb_vad_fx( move16(); /* needed for st_fx->vadnoise_fx update below */ } /* end of NB */ + /* *flag_noisy_speech_snr is a Word8 parameter */ *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); @@ -1628,6 +1647,7 @@ Word16 wb_vad_fx( move16(); } + IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); @@ -1648,19 +1668,19 @@ Word16 wb_vad_fx( } Word16 wb_vad_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ - const Word16 q_fr_bands, /* i : Q of fr_bands */ - Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ - Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ - Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ - Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ - Word16 *localVAD_HE_SAD, /* o : HE-SAD flag without hangover */ - Word16 *flag_noisy_speech_snr, /* o : encoder detector for noisy speech */ - VAD_HANDLE hVAD, /* i/o: VAD data handle */ - NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ - Word16 lp_noise_fx /* i : long term noise energy Q8 */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ + const Word16 q_fr_bands, /* i : Q of fr_bands */ + Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ + Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ + Word16 *NB_speech_HO, /* o : SC-VBR NB speech HO flag */ + Word16 *snr_sum_he, /* o : Output snr_sum as weighted spectral measure*/ + Word16 *localVAD_HE_SAD, + Word16 *flag_noisy_speech_snr, /* o : */ + VAD_HANDLE hVAD, /* i/o: VAD data handle */ + NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ + Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ + Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) { Word16 i, flag = 0, hangover_short; @@ -1787,12 +1807,11 @@ Word16 wb_vad_ivas_fx( last_7k2_coder_type = -1; move16(); } - /*---------------------------------------------------------------------* * set SNR thresholds depending on the input bandwitdh *---------------------------------------------------------------------*/ - - IF( EQ_16( st_fx->max_band, 19 ) ) /* WB input or SWB input */ + IF( EQ_16( st_fx->max_band, 19 ) ) + /* WB input */ /* or SWB input */ { nk = 3277; move16(); /*0.1 Q15 */ @@ -1827,6 +1846,7 @@ Word16 wb_vad_ivas_fx( } ELSE /* NB input */ { + // move16(); nk = 3277; move16(); /* 0.1 Q15 */ nc = 268435456; @@ -1879,6 +1899,7 @@ Word16 wb_vad_ivas_fx( move16(); } + IF( snr_idx == 0 ) { stmp = 6; @@ -1892,6 +1913,7 @@ Word16 wb_vad_ivas_fx( delta4 = 0; move32(); /*0.0f in Q16 */ + /*vad_thr = 2.4f*lp_snr - 42.2f; vad_thr = min(vad_thr, 80 ); */ @@ -2249,6 +2271,7 @@ Word16 wb_vad_ivas_fx( test(); IF( LT_32( L_accum_ener_H, Mult_32_16( L_accum_ener_L, INV_OUTLIER_THR_1_FX ) ) /* float:: (accum_ener_L*INV_OUTLIER_THR_1 > accum_ener_H ) !!! */ || LT_32( L_snr_outlier_Q4, MAX_SNR_OUTLIER_1_FX ) ) + { /* snr_sum_ol = SNR_OUTLIER_WGHT_1 * ( snr_sum_ol - snr_outlier ); As SNR_OUTLIER_WGHT_1 is 1.0f we do not need to multiply here , i.e. no need to loose any precisison */ @@ -2295,10 +2318,10 @@ Word16 wb_vad_ivas_fx( *snr_sum_he = snr_sum_HE_SAD; move16(); /* *snr_sum_he=snr_sum_HE_SAD; */ + /*---------------------------------------------------------------------* * compute thr1 for SAD decision *---------------------------------------------------------------------*/ - lp_snr = sub( lp_speech_fx, lp_noise_fx ); /*Q8*/ IF( LT_16( lp_snr, hNoiseEst->sign_dyn_lp_fx ) ) @@ -2346,6 +2369,7 @@ Word16 wb_vad_ivas_fx( } } + /*---------------------------------------------------------------------* * WB input * SNR threshold computing @@ -2354,6 +2378,7 @@ Word16 wb_vad_ivas_fx( IF( vad_bwidth_fx != NB ) { + /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of modyfying thr1 and snr_sum */ @@ -2465,6 +2490,7 @@ Word16 wb_vad_ivas_fx( move16(); } + IF( GT_16( hVAD->voiced_burst, 3 ) ) { IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) /* Q4 */ @@ -2479,6 +2505,7 @@ Word16 wb_vad_ivas_fx( } } + hangover_hd = hangover_hd_tbl[snr_idx]; move16(); @@ -2521,6 +2548,7 @@ Word16 wb_vad_ivas_fx( move16(); } + /* Calculate background stationarity */ test(); IF( flag_he1 == 0 && hNoiseEst->first_noise_updt > 0 ) @@ -2739,6 +2767,7 @@ Word16 wb_vad_ivas_fx( } } + thr2 = sub( thr1_nb_mod, 384 ); /*thr2 = thr1 - 1.5f; , clean speech */ /* -dtx condition dependency in noisy speech */ @@ -2754,6 +2783,7 @@ Word16 wb_vad_ivas_fx( thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } + flag = 0; move16(); IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ @@ -2762,6 +2792,7 @@ Word16 wb_vad_ivas_fx( move16(); } + test(); IF( ( LT_16( snr_sum, thr1_nb_mod ) ) && ( GT_16( snr_sum, thr2 ) ) ) /* Speech present */ { @@ -2780,6 +2811,7 @@ Word16 wb_vad_ivas_fx( move16(); /* needed for st_fx->vadnoise_fx update below */ } /* end of NB */ + /* *flag_noisy_speech_snr is a Word8 parameter */ *flag_noisy_speech_snr = 0; /*_DIFF_FLOAT_FIX_IVAS -> this initialisation is not done here in float */ move16(); @@ -2891,6 +2923,7 @@ Word16 wb_vad_ivas_fx( move16(); } + IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); /*Q0*/ -- GitLab From 23c91b83e5db1dfbca9e2b656edee640d8ff8227 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 20:34:57 +0100 Subject: [PATCH 5/9] fix + _fx appendix to function names --- lib_com/prot_fx.h | 27 +++++++------- lib_dec/core_dec_init_fx.c | 2 +- lib_dec/dec_LPD_fx.c | 4 +- lib_dec/dec_tcx_fx.c | 10 ++--- lib_dec/er_util_fx.c | 4 +- lib_dec/ivas_mdct_core_dec_fx.c | 8 ++-- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 3 +- lib_dec/ivas_tcx_core_dec_fx.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 51 ++++++++++++++++---------- 9 files changed, 62 insertions(+), 49 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 6e282c7d2..bbd83ad8f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5982,6 +5982,7 @@ void ivas_RefineTonalComponents_fx( const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ); +#ifndef HARMONIZE_FUNC ivas_error PsychoacousticParameters_Init( const Word32 sr_core, /* i : sampling rate of core-coder */ const Word16 nBins, /* i : Number of bins (spectral lines) */ @@ -5989,8 +5990,8 @@ ivas_error PsychoacousticParameters_Init( const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ PsychoacousticParameters *pPsychParams ); - -ivas_error TonalMDCTConceal_Init( +#endif +ivas_error TonalMDCTConceal_Init_fx( TonalMDCTConcealPtr self, const Word16 nSamples, const Word16 nSamplesCore, @@ -6007,7 +6008,7 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( ); /* Must be called only when a good frame is recieved - concealment is inactive */ -void TonalMDCTConceal_SaveFreqSignal( +void TonalMDCTConceal_SaveFreqSignal_fx( TonalMDCTConcealPtr self, const Word32 *mdctSpectrum, const Word16 mdctSpectrum_exp, @@ -6028,21 +6029,21 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( const Word16 gain_tcx_exp, const Word16 infoIGFStartLine ); -void TonalMDCTConceal_UpdateState( +void TonalMDCTConceal_UpdateState_fx( TonalMDCTConcealPtr self, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, - Word8 tonalConcealmentActive ); + const Word16 nNewSamples, + const Word32 pitchLag, + const Word16 badBlock, + const Word8 tonalConcealmentActive ); -void TonalMDCTConceal_Detect( +void TonalMDCTConceal_Detect_fx( const TonalMDCTConcealPtr self, /*IN */ const Word32 pitchLag, /*IN */ Word16 *umIndices, /*OUT*/ - Word16 element_mode /* IN */ + const Word16 element_mode /* IN */ ); -void TonalMDCTConceal_Apply( +void TonalMDCTConceal_Apply_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, /*IN/OUT*/ Word16 *mdctSpectrum_exp /*IN */ @@ -6068,7 +6069,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( const Word16 cngLevelBackgroundTrace_e, const Word16 crossOverFreq ); -void TonalMDCTConceal_InsertNoise( +void TonalMDCTConceal_InsertNoise_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, /*OUT*/ Word16 *mdctSpectrum_exp, /*OUT*/ @@ -6078,7 +6079,7 @@ void TonalMDCTConceal_InsertNoise( Word16 crossfadeGain, const Word16 crossOverFreq ); -void TonalMDCTConceal_SaveTimeSignal( +void TonalMDCTConceal_SaveTimeSignal_fx( TonalMDCTConcealPtr hTonalMDCTConc, Word16 *timeSignal, Word16 nNewSamples ); diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 7e18111c8..a6f52e9ee 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -965,7 +965,7 @@ void open_decoder_LPD_fx( st->hTonalMDCTConc->lastBlockData.nSamples = 0; move16(); - TonalMDCTConceal_Init( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); + TonalMDCTConceal_Init_fx( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } st->last_tns_active = 0; move16(); diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index d8eb395c5..d9e98458a 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -631,7 +631,7 @@ void decoder_LPD_fx( /* PLC: [TCX: Tonal Concealment] */ /* Signal that this frame is not TCX */ - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, 0, 0, 0, 0 ); IF( bfi == 0 ) { @@ -768,7 +768,7 @@ void decoder_LPD_fx( IF( !bfi ) { - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB, L_frameTCX ); + TonalMDCTConceal_SaveTimeSignal_fx( st->hTonalMDCTConc, synthFB, L_frameTCX ); } decoder_tcx_post_fx( st, synth, synthFB, Aq, bfi ); IF( EQ_16( st->core, TCX_20_CORE ) ) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0f5f1ec57..cdcee3d37 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -814,7 +814,7 @@ void decoder_tcx_fx( IF( bfi == 0 ) { - TonalMDCTConceal_SaveFreqSignal( st->hTonalMDCTConc, x, x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e ); + TonalMDCTConceal_SaveFreqSignal_fx( st->hTonalMDCTConc, x, x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e ); } ELSE { @@ -884,7 +884,7 @@ void decoder_tcx_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); - TonalMDCTConceal_InsertNoise( st->hTonalMDCTConc, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, + TonalMDCTConceal_InsertNoise_fx( st->hTonalMDCTConc, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, infoIGFStartLine ); } @@ -969,7 +969,7 @@ void decoder_tcx_fx( test(); IF( bfi && st->tonal_mdct_plc_active ) { - TonalMDCTConceal_Apply( st->hTonalMDCTConc, x, &x_e ); + TonalMDCTConceal_Apply_fx( st->hTonalMDCTConc, x, &x_e ); } tmp32 = L_deposit_h( 0 ); @@ -986,7 +986,7 @@ void decoder_tcx_fx( move16(); } - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX, tmp32, bfi, tmp8 ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX, tmp32, bfi, tmp8 ); IF( st->enablePlcWaveadjust ) { @@ -5221,7 +5221,7 @@ void decoder_tcx_noiseshaping_igf_fx( move16(); } - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX, tmp32, bfi, diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index e07a0717d..f24acb986 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_fx( } ELSE { - TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode ); + TonalMDCTConceal_Detect_fx( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode ); } #endif // !HARMONIZE_2427_GETPLC @@ -592,7 +592,7 @@ Word16 GetPLCModeDecision_fx( pitch = L_add( st->old_fpitch, 0 ); /*Q16*/ } - TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode ); + TonalMDCTConceal_Detect_fx( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode ); test(); test(); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 39694bdcb..eea0d9a27 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1349,7 +1349,7 @@ void ivas_mdct_core_reconstruct_fx( /* Signal that this frame is not TCX */ IF( st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, 0, 0, 0, 0 ); } Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); Scale_sig( st->mem_syn_r, M, st->Q_syn ); @@ -1564,7 +1564,7 @@ void ivas_mdct_core_tns_ns_fx( { IF( st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, 0, bfi, 0 ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, 0, bfi, 0 ); } /* nothing to do for missing LFE */ @@ -1733,11 +1733,11 @@ void ivas_mdct_core_tns_ns_fx( { IF( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], st->old_fpitch, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], st->old_fpitch, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); } ELSE { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], 0, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], 0, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); } } } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 2b4e57596..49965be36 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -433,8 +433,7 @@ void stereo_mdct_core_dec_fx( } move32(); - // TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ? st->old_fpitch : 0, bfi, bfi && st->tonal_mdct_plc_active ); - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], L_tmp, bfi, bfi && st->tonal_mdct_plc_active ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], L_tmp, bfi, bfi && st->tonal_mdct_plc_active ); } Copy( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); /* Q0 */ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 19025b403..68eb31a12 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -522,7 +522,7 @@ void stereo_tcx_core_dec_fx( /* Signal that this frame is not TCX */ IF( st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, 0, 0, 0, 0 ); + TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, 0, 0, 0, 0 ); } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0535c5d86..a072cd4c3 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -34,7 +34,7 @@ static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word /*-------------- public functions -------------------- */ /*******************************************************/ -ivas_error TonalMDCTConceal_Init( +ivas_error TonalMDCTConceal_Init_fx( TonalMDCTConcealPtr hTonalMDCTConc, const Word16 nSamples, const Word16 nSamplesCore, @@ -86,7 +86,6 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer; move16(); - hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) ) @@ -117,6 +116,8 @@ ivas_error TonalMDCTConceal_Init( return IVAS_ERR_OK; } + + ivas_error TonalMDCTConceal_Init_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, const UWord16 nSamples, @@ -222,7 +223,7 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( } -void TonalMDCTConceal_SaveFreqSignal( +void TonalMDCTConceal_SaveFreqSignal_fx( TonalMDCTConcealPtr hTonalMDCTConc, const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp const Word16 mdctSpectrum_exp, @@ -235,7 +236,6 @@ void TonalMDCTConceal_SaveFreqSignal( Word16 *temp; Word16 nOldSamples, tmp_exp, s, i, max_exp; - assert( nNewSamples > 0 && nNewSamples <= 2 * L_FRAME_MAX ); /* Avoid overwriting hTonalMDCTConc->secondLastPowerSpectrum stored in spectralData, @@ -349,9 +349,11 @@ void TonalMDCTConceal_SaveFreqSignal( Copy( scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors ); } + return; } + void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp @@ -511,12 +513,12 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( } -void TonalMDCTConceal_UpdateState( +void TonalMDCTConceal_UpdateState_fx( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, // Q0 - Word32 pitchLag, // Qx - Word16 badBlock, // Q0 - Word8 tonalConcealmentActive ) + const Word16 nNewSamples, // Q0 + const Word32 pitchLag, // Qx + const Word16 badBlock, // Q0 + const Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; @@ -571,7 +573,6 @@ static void FindPhases( Word16 l; Word16 *pCurrentPhase; - pCurrentPhase = hTonalMDCTConc->pTCI->phase_currentFramePredicted; /* for each index/index group */ FOR( i = 0; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) @@ -589,6 +590,7 @@ static void FindPhases( return; } + /*#define BANDWIDTH 7.0f*/ #define G 789516047l /*1.0/(2*1.36) Q31*/ #define MAXRATIO 22938 /*44.8f Q9*/ /* Maximum ratio |ODFT[k-1]|/|ODFT[k+1]| is 16.5 dB, that is maximum ratio (for fractional = 0) is (cos(PI/bandwidth)/cos(3PI/bandwidth))^1.36 */ @@ -712,6 +714,7 @@ static void FindPhaseDifferences( return; } + #ifdef HARMONIZE_FUNC static void CalcPowerSpecAndDetectTonalComponents_fx( #else @@ -778,6 +781,13 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } #ifdef HARMONIZE_FUNC + Word16 spectralData_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); + if ( element_mode == EVS_MONO ) + { + spectralData_exp = add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ); + } + DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -785,7 +795,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc->lastPitchLag, pitchLag, hTonalMDCTConc->lastBlockData.spectralData, - hTonalMDCTConc->lastBlockData.spectralData_exp, + spectralData_exp, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors_exp, hTonalMDCTConc->lastBlockData.scaleFactors_max_e, @@ -1063,13 +1073,15 @@ static void CalcMDXT( TCX_MDCT( windowedTimeSignal, mdxtOutput, mdxtOutput_e, left_overlap, sub( L_frame, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, EVS_MONO ); } + + return; } -void TonalMDCTConceal_Detect( +void TonalMDCTConceal_Detect_fx( const TonalMDCTConcealPtr hTonalMDCTConc, const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, - Word16 element_mode ) + const Word16 element_mode ) { Word32 secondLastMDST[L_FRAME_MAX]; Word32 secondLastMDCT[L_FRAME_MAX]; @@ -1078,7 +1090,6 @@ void TonalMDCTConceal_Detect( Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; Word16 nSamples; - nSamples = hTonalMDCTConc->nSamples; move16(); secondLastMDST_exp = 16; /*time signal Q-1*/ @@ -1203,7 +1214,6 @@ void TonalMDCTConceal_Detect( *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); - return; } @@ -2190,7 +2200,7 @@ return; } -void TonalMDCTConceal_InsertNoise( +void TonalMDCTConceal_InsertNoise_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, // Q31- *mdctSpectrum_exp /*OUT*/ Word16 *mdctSpectrum_exp, /*OUT*/ @@ -2486,7 +2496,6 @@ void TonalMDCTConceal_InsertNoise( /*make a headroom for mdct_shaping*/ exp = sub( *mdctSpectrum_exp, SPEC_EXP_DEC ); - IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; @@ -2592,7 +2601,7 @@ void TonalMDCTConceal_InsertNoise( return; } -void TonalMDCTConceal_Apply( +void TonalMDCTConceal_Apply_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 *mdctSpectrum_exp /*IN */ @@ -2861,7 +2870,7 @@ void TonalMDCTConceal_Apply_ivas_fx( return; } -void TonalMDCTConceal_SaveTimeSignal( +void TonalMDCTConceal_SaveTimeSignal_fx( TonalMDCTConcealPtr hTonalMDCTConc, Word16 *timeSignal, // Qx Word16 nNewSamples @@ -2958,6 +2967,8 @@ static void CalcPowerSpec( move32(); powerSpec[nSamples - 1] = L_shr( powerSpec[nSamples - 2], 1 ); move32(); + + return; } @@ -3368,4 +3379,6 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( } pop_wmops(); + + return; } -- GitLab From 218a3b3bdf57baf56a351bd46248278544bb4d1a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 21:35:19 +0100 Subject: [PATCH 6/9] clang-format --- lib_dec/dec_tcx_fx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index cdcee3d37..3a55418d6 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -885,8 +885,8 @@ void decoder_tcx_fx( tcxGetNoiseFillingTilt( A, M, L_frame, tmp, &noiseTiltFactor ); TonalMDCTConceal_InsertNoise_fx( st->hTonalMDCTConc, x, &x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, - noiseTiltFactor, f, - infoIGFStartLine ); + noiseTiltFactor, f, + infoIGFStartLine ); } } @@ -2267,7 +2267,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp8, fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); @@ -5222,10 +5222,10 @@ void decoder_tcx_noiseshaping_igf_fx( } TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, - L_frameTCX, - tmp32, - bfi, - tmp8 ); + L_frameTCX, + tmp32, + bfi, + tmp8 ); } *x_len = L_frameTCX; -- GitLab From 97ef54fda909838980938627f60d0303714bf956 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 21:38:12 +0100 Subject: [PATCH 7/9] clang-format --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 3a55418d6..0b98d4eac 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2267,7 +2267,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp8, fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); -- GitLab From efeddffab077134ea1cd3289155fbc9a5d3ab93c Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 4 Mar 2026 23:07:29 +0100 Subject: [PATCH 8/9] small complexity improvement --- lib_dec/TonalComponentDetection_fx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 8e92f4670..9b870cce4 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -104,11 +104,14 @@ void ivas_DetectTonalComponents_fx( pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ move32(); } + +#ifndef HARMONIZE_FUNC FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 move32(); } +#endif IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; @@ -119,6 +122,14 @@ void ivas_DetectTonalComponents_fx( } ELSE { +#ifdef HARMONIZE_FUNC + FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) + { + sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 + move32(); + } +#endif + q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore, NULL ); q_pScaledMdctSpectrum = add( q_pScaledMdctSpectrum, 1 ); -- GitLab From 24d8a9ccdea94d5eedfe5242d93bc6d5f67cb563 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 6 Mar 2026 11:04:37 +0100 Subject: [PATCH 9/9] address reviewer's comments --- lib_dec/TonalComponentDetection_fx.c | 9 ++++++--- lib_dec/tonalMDCTconcealment_fx.c | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 9b870cce4..1b09f98d2 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -97,8 +97,8 @@ void ivas_DetectTonalComponents_fx( lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); } ELSE -#endif { +#endif FOR( Word16 i = 0; i < nSamples; i++ ) { pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ @@ -151,7 +151,9 @@ void ivas_DetectTonalComponents_fx( /* Guard bit */ lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ +#ifdef HARMONIZE_FUNC } +#endif /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); @@ -771,6 +773,7 @@ static void findStrongestHarmonics( /* Use new F0, for which harmonics are most common in pHarmonicIndexes */ static void CorrectF0( +#ifndef HARMONIZE_FUNC const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ @@ -916,8 +919,8 @@ static void CorrectF0( return; } -#ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( +#endif const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ @@ -1070,7 +1073,7 @@ static void ivas_CorrectF0_fx( return; } -#endif + static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index a072cd4c3..4d290e72a 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -881,8 +881,8 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( #ifdef HARMONIZE_FUNC IF( element_mode != EVS_MONO ) -#endif { +#endif IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) @@ -894,7 +894,9 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 powerSpectrum_exp = add( powerSpectrum_exp, 3 ); +#ifdef HARMONIZE_FUNC } +#endif FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { @@ -908,12 +910,14 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); } ELSE -#endif { +#endif Word16 shift = Find_Max_Norm32( powerSpectrum, nSamples ); scale_sig32( powerSpectrum, nSamples, shift ); powerSpectrum_exp = sub( powerSpectrum_exp, shift ); +#ifdef HARMONIZE_FUNC } +#endif /* 16 bits are now enough for storing the power spectrum */ FOR( i = 0; i < nSamples; i++ ) -- GitLab