From 5c74348ae0bc21b6b588dd9882750bc8b8a0678a Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 27 Apr 2026 17:51:03 +0200 Subject: [PATCH 01/19] initial version for issue 1966, macros to be enabled to get debug prints and 16/32 bit variables --- lib_dec/TonalComponentDetection_fx.c | 108 +++++++++++++++++++++++++- lib_dec/er_util_fx.c | 24 ++++++ lib_dec/ivas_mdct_core_dec_fx.c | 37 +++++++++ lib_dec/tonalMDCTconcealment_fx.c | 111 ++++++++++++++++++++++++++- 4 files changed, 276 insertions(+), 4 deletions(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 2223bfa9c..4e6d3e56f 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,21 +12,47 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" +//#define FIX_ISSUE_1966 +//#define DEBUG_ISSUE_1966 + +#ifdef DEBUG_ISSUE_1966 +extern int32_t frame; +#endif /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); +#ifdef FIX_ISSUE_1966 +static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 F0_32, Word32 *envelope, Word32 *smoothedSpectrum ); +#else static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); +#endif static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); 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 ); +#ifdef FIX_ISSUE_1966 +static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, + Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum ); +#else static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); +#endif static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); +#ifdef FIX_ISSUE_1966 +static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, + Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32 ); +#else static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); +#endif + +#ifdef FIX_ISSUE_1966 +static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, + Word16 F0, Word32 F0_32, Word16 *thresholdModification, Word32 *thresholdModification32, Word16 element_mode ); +#else 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 ); +#endif /*-------------------------------------------------------------------* @@ -60,11 +86,18 @@ void DetectTonalComponents_fx( ) { Word16 F0; +#ifdef FIX_ISSUE_1966 + Word32 F0_32; + Word32 thresholdModification32[L_FRAME_MAX]; +#endif Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; Word32 pScaledMdctSpectrum[L_FRAME_MAX]; Word16 nBands; Word32 sns_int_scf_fx[FDNS_NPTS]; /*Q16*/ Word16 q_pScaledMdctSpectrum; +#ifdef DEBUG_ISSUE_1966 + printf("Calling DetectTonalComponents *pNumIndexes=%d\n", *pNumIndexes); +#endif set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); @@ -122,14 +155,27 @@ void DetectTonalComponents_fx( } /* Find peak candidates in the last frame. */ +#ifdef FIX_ISSUE_1966 + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, thresholdModification32, floorPowerSpectrum ); +#else findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); +#endif /* Refine peak candidates using the pitch information */ +#ifdef FIX_ISSUE_1966 + RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, &F0_32, + thresholdModification, thresholdModification32 ); +#else RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); +#endif /* Find peaks in the second last frame */ +#ifdef FIX_ISSUE_1966 + findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, + F0, F0_32, thresholdModification, thresholdModification32, element_mode ); +#else findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); - +#endif return; } @@ -296,6 +342,9 @@ static void getEnvelope( const Word16 nSamples, /*i : Q0 */ const Word32 *powerSpec, /*i : powerSpec_exp */ Word16 F0, /*i : 5Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 F0_32, /*i : 5Q10+Q16*/ +#endif Word32 *envelope, /*o : powerSpec_exp + LEVEL_EXP Q28*/ Word32 *smoothedSpectrum /*o : powerSpec_exp + LEVEL_EXP Q28*/ ) @@ -711,6 +760,14 @@ static void modifyThreshold( thresholdModification[k - 1] = add( threshold /*Q10*/, twoTimesFract /*Q10*/ ); /*Q10*/ move16(); thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ +#ifdef DEBUG_ISSUE_1966 + if (frame == 1384) + printf("modifyThreshold: [%d] %15.15f %15.15f %15.15f F0 %15.15f\n", k - 1, + (double) thresholdModification[k-1] / (1 << 10), + (double) thresholdModification[k+0] / (1 << 10), + (double) thresholdModification[k+1] / (1 << 10), + (double) F0 / (1 << 10) ); +#endif return; } @@ -763,6 +820,9 @@ static void findCandidates( const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ +#ifdef FIX_ISSUE_1966 + Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ +#endif Word16 floorPowerSpectrum /* i : lower limit for power spectrum bins Q0*/ ) { @@ -777,9 +837,17 @@ static void findCandidates( calcPseudoSpec( MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp ); +#ifdef FIX_ISSUE_1966 + getEnvelope( nSamples, powerSpectrum, 0, (Word32) 0, envelope, smoothedSpectrum ); +#else getEnvelope( nSamples, powerSpectrum, 0, envelope, smoothedSpectrum ); +#endif set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ +#ifdef FIX_ISSUE_1966 + set32_fx( thresholdModificationNew32, (UNREACHABLE_THRESHOLD) << 16, nSamples ); /*Q10+Q16*/ + +#endif k = GROUP_LENGTH / 2; move16(); @@ -873,11 +941,19 @@ static void findCandidates( { thresholdModificationNew[j] = BIG_THRESHOLD; /*Q10*/ move16(); +#ifdef FIX_ISSUE_1966 + thresholdModificationNew32[j] = BIG_THRESHOLD << 16; /* 1.5f in Q10+Q16*/ + move32(); +#endif if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) { thresholdModificationNew[j] = SMALL_THRESHOLD; /*Q10*/ move16(); +#ifdef FIX_ISSUE_1966 + thresholdModificationNew32[j] = 73819750; /* 1.1f in Q10+Q16*/ + move32(); +#endif } } /* Jump to the next foot of the peak. */ @@ -901,7 +977,13 @@ static void findTonalComponents_fx( const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, Word16 F0, /* IN */ +#ifdef FIX_ISSUE_1966 + Word32 F0_32, /* IN */ +#endif Word16 *thresholdModification, /* IN Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 *thresholdModification32, /* IN Q10+Q16*/ +#endif Word16 element_mode ) /* IN */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -912,7 +994,21 @@ static void findTonalComponents_fx( Word32 biggerNeighbor; Word16 tmp_loop1, tmp_loop2, tmp_loop3; +#ifdef DEBUG_ISSUE_1966 + if (frame == 1384) + { + for (j = 0; j < nSamples; j++) + { + printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) (1 << 10) ); + } + } +#endif + +#ifdef FIX_ISSUE_1966 + getEnvelope( nSamples, powerSpectrum, F0, F0_32, envelope, smoothedSpectrum ); +#else getEnvelope( nSamples, powerSpectrum, F0, envelope, smoothedSpectrum ); +#endif nrOfFIS = 0; move16(); @@ -1047,6 +1143,10 @@ static void findTonalComponents_fx( indexOfTonalPeak[nrOfFIS++] = k; move16(); +#ifdef DEBUG_ISSUE_1966 + if ( frame == 1384 ) + printf( "nrOfFIS=%d k=%d\n", nrOfFIS , k); +#endif IF( EQ_16( nrOfFIS, MAX_NUMBER_OF_IDX ) ) { @@ -1073,7 +1173,13 @@ static void RefineThresholdsUsingPitch_fx( const Word32 lastPitchLag, /*Qx*/ const Word32 currentPitchLag, /*Qx*/ Word16 *pF0, /*Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 *pF0_32, /*Q10+Q16*/ +#endif Word16 *thresholdModification /*Q10*/ +#ifdef FIX_ISSUE_1966 + , Word32 *thresholdModification32 /*Q10+Q16*/ +#endif ) { Word16 pitchIsStable; diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 78fb12f10..9c5b13242 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -11,6 +11,12 @@ #include "ivas_prot_fx.h" +//#define DEBUG_ISSUE_1966 + +#ifdef DEBUG_ISSUE_1966 +extern int32_t frame; +#endif + /* static void setnoiseLevelMemory_fx() * * Helper function - updates buffer for minimumStatistics_fx function @@ -375,6 +381,9 @@ Word16 GetPLCModeDecision_fx( TCX_DEC_HANDLE hTcxDec; hTcxDec = st->hTcxDec; +#ifdef DEBUG_ISSUE_1966 + printf("Calling GetPLCModeDecision in frame=%d\n", frame); +#endif IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { @@ -410,6 +419,9 @@ Word16 GetPLCModeDecision_fx( } st->tonal_mdct_plc_active = 0; move16(); +#ifdef DEBUG_ISSUE_1966 + printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); +#endif } ELSE { @@ -427,6 +439,9 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); +#ifdef DEBUG_ISSUE_1966 + printf( "-->tonal_mdct_plc_active=%d F2\n", st->tonal_mdct_plc_active ); +#endif IF( !( st->rf_flag && st->use_partial_copy && ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) || EQ_16( st->rf_frame_type, RF_TCXTD2 ) ) ) ) { test(); @@ -459,12 +474,18 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); +#ifdef DEBUG_ISSUE_1966 + printf("-->pitch=%f numIndices=%2d\n", (double) pitch / (double) (1 << 16), numIndices); +#endif IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { core = TCX_20_CORE; move16(); st->tonal_mdct_plc_active = 1; move16(); +#ifdef DEBUG_ISSUE_1966 + printf( "-->tonal_mdct_plc_active=%d F21\n", st->tonal_mdct_plc_active ); +#endif } ELSE IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { @@ -484,6 +505,9 @@ Word16 GetPLCModeDecision_fx( } } } +#ifdef DEBUG_ISSUE_1966 + printf( "X->tonal_mdct_plc_active=%d F3\n", st->tonal_mdct_plc_active ); +#endif return core; /*Q0*/ } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 61c4bf0ce..9961fd771 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -40,7 +40,11 @@ #include "basop_proto_func.h" #include "ivas_prot_fx.h" +//#define DEBUG_ISSUE_1966 +#ifdef DEBUG_ISSUE_1966 +extern int32_t frame; +#endif /*-----------------------------------------------------------------* * Function mdct_read_IGF_bits() * @@ -1516,6 +1520,10 @@ void ivas_mdct_core_tns_ns_fx( Word16 exp, length; #endif +#ifdef DEBUG_ISSUE_1966 + printf("Calling ivas_mdct_core_tns_ns in frame=%d\n", frame); +#endif + /* Initializations */ sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; @@ -1529,6 +1537,9 @@ void ivas_mdct_core_tns_ns_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F1\n", ch, st->tonal_mdct_plc_active ); +#endif #ifdef FIX_BASOP_2555_FRAMELEN_CALC IF( EQ_16( st->core, TCX_20_CORE ) ) { @@ -1590,6 +1601,10 @@ void ivas_mdct_core_tns_ns_fx( IF( st->hTonalMDCTConc != NULL ) { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, 0, bfi, 0 ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F2\n", ch, st->tonal_mdct_plc_active ); +#endif + } /* nothing to do for missing LFE */ @@ -1601,6 +1616,10 @@ void ivas_mdct_core_tns_ns_fx( init_tcx_info_fx( st, L_frame_global[ch], L_frameTCX_glob[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F3 k=%d\n", ch, st->tonal_mdct_plc_active, k ); +#endif + Word16 q_x; q_x = sub( 31, x_e ); IF( bfi == 0 ) @@ -1622,6 +1641,9 @@ void ivas_mdct_core_tns_ns_fx( move16(); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline_fx( st, L_frame[ch], L_frameTCX[ch] ) ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F4 k=%d\n", ch, st->tonal_mdct_plc_active, k ); +#endif } } ELSE @@ -1680,6 +1702,9 @@ void ivas_mdct_core_tns_ns_fx( } Scale_sig32( &x_fx[ch][k][0], length, -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1, &length ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F5 k=%d\n", ch, st->tonal_mdct_plc_active, k ); +#endif norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); @@ -1738,6 +1763,9 @@ void ivas_mdct_core_tns_ns_fx( } Scale_sig32( &x_fx[ch][k][0], length, -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0, &length ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F6 k=%d\n", ch, st->tonal_mdct_plc_active, k ); +#endif Scale_sig32( &x_fx[ch][k][0], length, sub( sub( 31, q_x ), x_e ) ); } @@ -1750,6 +1778,9 @@ void ivas_mdct_core_tns_ns_fx( } TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], x_e, st->hTcxCfg->psychParamsCurrent ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d F7\n", ch, st->tonal_mdct_plc_active ); +#endif } test(); @@ -1759,10 +1790,16 @@ void ivas_mdct_core_tns_ns_fx( IF( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], st->old_fpitch, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d bfi=%d F8-A\n", ch, st->tonal_mdct_plc_active, bfi ); +#endif } ELSE { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], 0, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); +#ifdef DEBUG_ISSUE_1966 + printf( "->ch=%d tonal_mdct_plc_active=%d bfi=%d F8-B\n", ch, st->tonal_mdct_plc_active, bfi ); +#endif } } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index e45aac27c..64331df0e 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -13,6 +13,12 @@ #include "stat_com.h" #include "ivas_prot_fx.h" +//#define DEBUG_ISSUE_1966 + +#ifdef DEBUG_ISSUE_1966 +extern int32_t frame; +#endif + #define CROSSFADE_THRESHOLD ( 32762 ) // close to 1.0f in Q15 such that (x == 1.0f) is true /************************************************************************************ @@ -517,6 +523,10 @@ void TonalMDCTConceal_UpdateState_fx( const Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; +#ifdef DEBUG_ISSUE_1966 + printf("Calling TonalMDCTConceal_UpdateState in frame=%d: ns=%d pl=%f bB=%d tCA=%d\n", + frame, nNewSamples, (double) pitchLag / (double) (1 << 16), badBlock, tonalConcealmentActive); +#endif assert( !( !badBlock && tonalConcealmentActive ) ); @@ -606,6 +616,11 @@ static void FindPhaseDifferences( Word16 divi, s, j; Word32 a, Q, L_tmp, m, n; +#ifdef DEBUG_ISSUE_1966 + int a_way; + printf( "Calling FindPhaseDifferences: numIndexes=%d frame=%d\n", hTonalMDCTConc->pTCI->numIndexes, frame ); +#endif + s = SS; move16(); j = J; @@ -627,11 +642,33 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); +#if 0 if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; move16(); } +#else + if ( EQ_16( s_and( k, 3 ), 1 ) ) + { + phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 2 ) ) + { + phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 3 ) ) + { + phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; + move16(); + } +#endif +#ifdef DEBUG_ISSUE_1966 + fractional = 0; // only for debug + a_way = 1; +#endif } ELSE { @@ -639,11 +676,33 @@ static void FindPhaseDifferences( { phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); +#if 0 if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ move16(); } +#else + if ( EQ_16( s_and( k, 3 ), 1 ) ) + { + phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 2 ) ) + { + phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 3 ) ) + { + phaseDiff[i] = 0 /* 0*EVS_PI 3Q12*/; + move16(); + } +#endif +#ifdef DEBUG_ISSUE_1966 + fractional = 0; // only for debug + a_way = 2; +#endif } ELSE { @@ -703,8 +762,20 @@ static void FindPhaseDifferences( } phaseDiff[i] = round_fx( L_shl( L_tmp, 1 ) ); /*3Q12*/ move16(); +#ifdef DEBUG_ISSUE_1966 + a_way = 3; +#endif } } +#ifdef DEBUG_ISSUE_1966 + printf( "phaseDiff[%3d]=%15.15f frac=%15.15f a_way=%d\n l/r=%15.15f k=%d\n", + i, + (double) phaseDiff[i] / (double) (1 << 12), + ( a_way == 3 ) ? (double) L_mult(fractional, 28672) / (double) (1 << 27) : 0.f, + a_way, + (double) powerSpectrum[k - 1] / (double) powerSpectrum[k + 1], + hTonalMDCTConc->pTCI->indexOfTonalPeak[i] ); +#endif } return; @@ -777,6 +848,9 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( spectralData_exp = add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ); } +#ifdef DEBUG_ISSUE_1966 + printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); +#endif DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -793,7 +867,9 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); - +#ifdef DEBUG_ISSUE_1966 + printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); +#endif FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); @@ -944,9 +1020,12 @@ void TonalMDCTConceal_Detect_fx( Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; Word16 nSamples; Word32 sns_int_scf_fx[FDNS_NPTS]; +#ifdef DEBUG_ISSUE_1966 + Word32 det_way = 0; + printf( "Calling TonalMDCTConceal_Detect in frame=%d *numIndices=%d ->numIndexes=%d\n", frame, *numIndices, hTonalMDCTConc->pTCI->numIndexes ); +#endif set32_fx( sns_int_scf_fx, 0, FDNS_NPTS ); - nSamples = hTonalMDCTConc->nSamples; move16(); @@ -975,6 +1054,10 @@ void TonalMDCTConceal_Detect_fx( { IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { +#ifdef DEBUG_ISSUE_1966 + det_way = 1; +#endif + CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; @@ -1023,6 +1106,9 @@ void TonalMDCTConceal_Detect_fx( } ELSE { +#ifdef DEBUG_ISSUE_1966 + det_way = 2; +#endif /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ Word16 temp_power_spectrum_q = 0; @@ -1035,6 +1121,9 @@ void TonalMDCTConceal_Detect_fx( } IF( psychParamsCurrent == NULL ) { +#ifdef DEBUG_ISSUE_1966 + det_way = 21; +#endif mdct_shaping_16( hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum ); @@ -1054,6 +1143,9 @@ void TonalMDCTConceal_Detect_fx( } ELSE { +#ifdef DEBUG_ISSUE_1966 + det_way = 22; +#endif FOR( i = 0; i < FDNS_NPTS; i++ ) { sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], add( 1, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q16 @@ -1070,7 +1162,9 @@ void TonalMDCTConceal_Detect_fx( } powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } - +#ifdef DEBUG_ISSUE_1966 + printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); +#endif RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -1089,15 +1183,26 @@ void TonalMDCTConceal_Detect_fx( nSamples, hTonalMDCTConc->nSamplesCore, extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ +#ifdef DEBUG_ISSUE_1966 + printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); +#endif } } } ELSE { +#ifdef DEBUG_ISSUE_1966 + det_way = 3; +#endif + hTonalMDCTConc->pTCI->numIndexes = 0; move16(); } +#ifdef DEBUG_ISSUE_1966 + printf( "Using TonalMDCTConceal_Detect in path=%d\n", det_way ); +#endif + *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); -- GitLab From 99f7595a9ec8d79bbeb26aca557a5f9eec7be07c Mon Sep 17 00:00:00 2001 From: gerstack Date: Wed, 29 Apr 2026 09:36:42 +0200 Subject: [PATCH 02/19] added new 32bit calculations --- lib_dec/TonalComponentDetection_fx.c | 236 +++++++++++++++++++++++++-- 1 file changed, 223 insertions(+), 13 deletions(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 4e6d3e56f..c943b4eae 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,8 +12,12 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -//#define FIX_ISSUE_1966 -//#define DEBUG_ISSUE_1966 +#define FIX_ISSUE_1966 +#define DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 +#include +#include +#endif #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -29,7 +33,15 @@ static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 #else static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); #endif -static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, +#ifdef FIX_ISSUE_1966 + Word32 *const pOrigF0_32, +#endif + Word16 *const pF0 +#ifdef FIX_ISSUE_1966 + , Word32 *const pF0_32 +#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 ); #ifdef FIX_ISSUE_1966 @@ -38,8 +50,34 @@ static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, c #else static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); #endif -static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); -static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); +static void modifyThreshold( Word16 i, Word16 F0, +#ifdef FIX_ISSUE_1966 + Word32 F0_32, +#endif + Word16 threshold, +#ifdef FIX_ISSUE_1966 + Word32 threshold_32, +#endif + Word16 *thresholdModification +#ifdef FIX_ISSUE_1966 + , + Word32 *thresholdModification_32 +#endif +); +static void modifyThresholds( Word16 F0, +#ifdef FIX_ISSUE_1966 + Word32 F0_32, +#endif + Word16 origF0, +#ifdef FIX_ISSUE_1966 + Word32 origF0_32, +#endif + Word16 *thresholdModification +#ifdef FIX_ISSUE_1966 + , + Word32 *thresholdModification_32 +#endif +); #ifdef FIX_ISSUE_1966 static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32 ); @@ -54,6 +92,44 @@ static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex 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 ); #endif +#ifdef FIX_ISSUE_1966 +static inline int32_t double_to_q31_with_exp(double x, int *out_exp) { + // Zerlege x in Mantisse und Exponent: x = m * 2^e, m in [0.5, 1) oder (-1, -0.5] + int e; + double m = frexp(x, &e); // x = m * 2^e, mit |m| in (0.5, 1] + + // Normalisiere so, dass |m| in [0.5, 1). Wir möchten später m in [-1,1) skalieren. + // Wir wählen hier eine Darstellung mit Mantisse in [-1, 1). + // Skaliere Mantisse weiter nach [-1, 1) falls nötig: + // Keep m wie von frexp (|m| in (0.5,1]). Wir skalieren bei Bedarf: + // Wir wollen final m_q31 = round(m * 2^31) und e beibehalten, aber sicherstellen + // dass der resultierende Wert im Q31-Bereich liegt. + + // In Q31 kann Mantisse m_q31 = round(m * 2^31). + // Grenzen beachten: |m| < 1, also m_q31 liegt in (-2^31, 2^31-1). Wir saturieren ggf. + double scaled = m * (double)(1ULL << 31); // 2^31 + // Rundung + if (scaled >= 0.0) + scaled += 0.5; + else + scaled -= 0.5; + + // Saturation in int32_t + if (scaled > (double)INT32_MAX) scaled = (double)INT32_MAX; + if (scaled < (double)INT32_MIN) scaled = (double)INT32_MIN; + + int32_t m_q31 = (int32_t)scaled; + + if (out_exp) *out_exp = e; + + return m_q31; +} +// Optionaler Helper: Mantisse aus Q31 zurück zu double (nur zur Überprüfung) +static inline double q31_to_double(int32_t q31) { + // q31 → double in [-1, 1) + return ((double)q31) / (double)(1ULL << 31); +} +#endif /*-------------------------------------------------------------------* * DetectTonalComponents() @@ -444,7 +520,14 @@ static void GetF0( /*i - Qx */ /*is justed handed over and given back*/ Word32 /*int*/ const pitchLag, /*i - Q16*/ Word16 /*short*/ *const pOrigF0, /*o - Q10*/ - Word16 /*short*/ *const pF0 ) /*o - Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 *const pOrigF0_32, +#endif + Word16 /*short*/ *const pF0 /*o - Q10*/ +#ifdef FIX_ISSUE_1966 + , Word32 *const pF0_32 +#endif +) { Word16 /*short*/ tmpPitchLag; Word16 /*short*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; /*Q0*/ @@ -467,9 +550,31 @@ static void GetF0( /**pF0 = nSamplesCore/tmpPitchLag;*/ BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ move16(); +#ifdef FIX_ISSUE_1966 + int tmp_32 = 0; + double k = nSamplesCore / (tmpPitchLag*0.5f*0.0625f); + *pF0_32 = double_to_q31_with_exp(k, &tmp_32); +#ifdef DEBUG_ISSUE_1966 + static float err_max=0.f; + double f1 = *pF0 * pow(2.f, -15+tmp); + float tmp2= err_max; + err_max= fmax( err_max, (f1-k)/k ); + if (err_max != tmp2) + printf("# frame=%d fx32=0x%08x fx16=0x%04x err=%0.5f,%f, exp: tmp=%d, tmp_32=%d \n", + frame, *pF0_32, *pF0, (f1-k)/k,err_max, tmp, tmp_32 ); +#endif + //assert(tmp_32 == tmp); + if (tmp_32 != tmp) printf("\n\n ERROR L:%d, tmp,tmp_32 = %d,%d\n\n\n", __LINE__, tmp,tmp_32); +#endif *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ +#ifdef FIX_ISSUE_1966 + *pF0_32 = L_shr_sat( *pF0_32, sub( 5, tmp_32 ) ); /*Q10 without scalingfactor*/ +#endif move16(); *pOrigF0 = *pF0; /*Q10*/ +#ifdef FIX_ISSUE_1966 + *pOrigF0_32 = *pF0_32; /*Q26*/ +#endif move16(); tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) @@ -477,8 +582,28 @@ static void GetF0( move16(); tmp = nSamples; } +#ifdef FIX_ISSUE_1966 + double k2 = ((Word32)tmp<<15) / (*pF0_32*pow(2.,-16+5)); + Word32 nTotalHarmonics_32 = double_to_q31_with_exp(k2, &tmp_32); +#endif BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); +#ifdef DEBUG_ISSUE_1966 + if (tmp != tmp_32) printf("tmp=%d tmp_32=%d\n", tmp,tmp_32 ); +#endif + assert( tmp == tmp_32 ); +#ifdef DEBUG_ISSUE_1966__ + printf("# frame=%d k2=%f fx16=%f, \n", + frame, k2, nTotalHarmonics*pow(2.,-15+tmp ) ); +#endif nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); +#ifdef FIX_ISSUE_1966 + nTotalHarmonics_32 = L_shl( nTotalHarmonics_32, L_sub( tmp_32, 31 ) ); +#ifdef DEBUG_ISSUE_1966___ + if (nTotalHarmonics != nTotalHarmonics_32) + printf("# nTotalHarmonics=%d nTotalHarmonics_32=%d\n", + nTotalHarmonics, nTotalHarmonics_32 ); +#endif +#endif /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); @@ -741,8 +866,19 @@ static void CorrectF0( static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ Word16 /*short*/ F0, /*I - Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 F0_32, /*I - Qi26*/ +#endif Word16 /*short*/ threshold, /*I - Q10*/ - Word16 * /*short*/ thresholdModification ) /*I/O - Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 threshold_32, /*I - Q26*/ +#endif + Word16 * /*short*/ thresholdModification /*I - Q10*/ +#ifdef FIX_ISSUE_1966 + , + Word32 * /*short*/ thresholdModification_32 +#endif +) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; @@ -775,8 +911,19 @@ static void modifyThreshold( static void modifyThresholds( Word16 /*short*/ F0, /*I - Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 F0_32, /*I - Qi26*/ +#endif Word16 /*short*/ origF0, /*I - Q10*/ - Word16 * /*short*/ thresholdModification ) /*I/O - Q10*/ +#ifdef FIX_ISSUE_1966 + Word32 origF0_32, /*I - Qi26*/ +#endif + Word16 * /*short*/ thresholdModification +#ifdef FIX_ISSUE_1966 + , + Word32 * /*short*/ thresholdModification_32 +#endif +) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; @@ -789,7 +936,20 @@ static void modifyThresholds( FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold( i, origF0, 717 /*0.7f Q10*/ /*0.7f in Q10*/, thresholdModification ); + modifyThreshold( i, origF0, +#ifdef DEBUG_ISSUE_1966 + origF0_32, +#endif + 717 /*0.7f Q10*/ /*0.7f in Q10*/, +#ifdef DEBUG_ISSUE_1966 + 717 * 0x10000, +#endif + thresholdModification +#ifdef DEBUG_ISSUE_1966 + , + thresholdModification_32 +#endif + ); } } IF( F0 > 0 ) @@ -802,11 +962,37 @@ static void modifyThresholds( FOR( i = tmp; i > 0; i-- ) { - modifyThreshold( i, origF0, 358 /*0.35f Q10*/, thresholdModification ); + modifyThreshold( i, origF0, +#ifdef DEBUG_ISSUE_1966 + origF0_32, +#endif + 358 /*0.35f Q10*/, +#ifdef DEBUG_ISSUE_1966 + 358 * 0x10000, +#endif + thresholdModification +#ifdef DEBUG_ISSUE_1966 + , + thresholdModification_32 +#endif + ); } FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold( i, F0, 358 /*0.35f Q10*/, thresholdModification ); + modifyThreshold( i, F0, +#ifdef DEBUG_ISSUE_1966 + origF0_32, +#endif + 358 /*0.35f Q10*/, +#ifdef DEBUG_ISSUE_1966 + 358 * 0x10000, +#endif + thresholdModification +#ifdef DEBUG_ISSUE_1966 + , + thresholdModification_32 +#endif + ); } } } @@ -1184,6 +1370,9 @@ static void RefineThresholdsUsingPitch_fx( { Word16 pitchIsStable; Word16 origF0; +#ifdef FIX_ISSUE_1966 + Word32 origF0_32; +#endif Word32 L_tmp; /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ @@ -1198,9 +1387,30 @@ static void RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { - GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); + GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, +#ifdef FIX_ISSUE_1966 + &origF0_32, +#endif + pF0 +#ifdef FIX_ISSUE_1966 + ,pF0_32 +#endif + ); - modifyThresholds( *pF0, origF0, thresholdModification ); + modifyThresholds( *pF0, +#ifdef FIX_ISSUE_1966 + *pF0_32, +#endif + origF0, +#ifdef FIX_ISSUE_1966 + origF0_32, +#endif + thresholdModification +#ifdef FIX_ISSUE_1966 + , + thresholdModification32 +#endif + ); } ELSE { -- GitLab From 0c0f9d93645c617724b48df612aa42b343af7690 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 29 Apr 2026 09:50:53 +0200 Subject: [PATCH 03/19] deactivated FIX and DEBUG stuff --- lib_dec/TonalComponentDetection_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index c943b4eae..d38144d9d 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,8 +12,8 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -#define FIX_ISSUE_1966 -#define DEBUG_ISSUE_1966 +//#define FIX_ISSUE_1966 +//#define DEBUG_ISSUE_1966 #ifdef FIX_ISSUE_1966 #include #include @@ -589,8 +589,8 @@ static void GetF0( BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); #ifdef DEBUG_ISSUE_1966 if (tmp != tmp_32) printf("tmp=%d tmp_32=%d\n", tmp,tmp_32 ); -#endif assert( tmp == tmp_32 ); +#endif #ifdef DEBUG_ISSUE_1966__ printf("# frame=%d k2=%f fx16=%f, \n", frame, k2, nTotalHarmonics*pow(2.,-15+tmp ) ); -- GitLab From eb836cefaff60c1e813a9af4a449011058dc36ad Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 29 Apr 2026 15:38:48 +0200 Subject: [PATCH 04/19] added draft version of GetF0, incl. division (newton) call and CorrectF0 subroutine --- lib_dec/TonalComponentDetection_fx.c | 162 +++++++++++++++++---------- 1 file changed, 104 insertions(+), 58 deletions(-) mode change 100644 => 100755 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100644 new mode 100755 index d38144d9d..702a02e9c --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -43,7 +43,11 @@ static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 cons #endif ); static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); +#ifdef FIX_ISSUE_1966 +static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0, Word32 *pF0_32 ); +#else static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); +#endif #ifdef FIX_ISSUE_1966 static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum ); @@ -172,7 +176,7 @@ void DetectTonalComponents_fx( Word32 sns_int_scf_fx[FDNS_NPTS]; /*Q16*/ Word16 q_pScaledMdctSpectrum; #ifdef DEBUG_ISSUE_1966 - printf("Calling DetectTonalComponents *pNumIndexes=%d\n", *pNumIndexes); + printf("Calling DetectTonalComponents in frame=%d\n", frame); #endif set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); @@ -549,33 +553,31 @@ static void GetF0( /**pF0 = nSamplesCore/tmpPitchLag;*/ BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ - move16(); -#ifdef FIX_ISSUE_1966 - int tmp_32 = 0; - double k = nSamplesCore / (tmpPitchLag*0.5f*0.0625f); - *pF0_32 = double_to_q31_with_exp(k, &tmp_32); -#ifdef DEBUG_ISSUE_1966 - static float err_max=0.f; - double f1 = *pF0 * pow(2.f, -15+tmp); - float tmp2= err_max; - err_max= fmax( err_max, (f1-k)/k ); - if (err_max != tmp2) - printf("# frame=%d fx32=0x%08x fx16=0x%04x err=%0.5f,%f, exp: tmp=%d, tmp_32=%d \n", - frame, *pF0_32, *pF0, (f1-k)/k,err_max, tmp, tmp_32 ); -#endif - //assert(tmp_32 == tmp); - if (tmp_32 != tmp) printf("\n\n ERROR L:%d, tmp,tmp_32 = %d,%d\n\n\n", __LINE__, tmp,tmp_32); -#endif *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ -#ifdef FIX_ISSUE_1966 - *pF0_32 = L_shr_sat( *pF0_32, sub( 5, tmp_32 ) ); /*Q10 without scalingfactor*/ -#endif move16(); *pOrigF0 = *pF0; /*Q10*/ + move16(); + #ifdef FIX_ISSUE_1966 + Word16 tmp_32 = 0; + Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton(L_shl(nSamplesCore, Q16), tmpPitchLag, &tmp_32); + if (tmp_32 != Q16) + F0_32 = L_shl(F0_32, tmp_32 - Q16); + *pF0_32 = F0_32; + move32(); *pOrigF0_32 = *pF0_32; /*Q26*/ + move32(); #endif - move16(); +#ifdef DEBUG_ISSUE_1966 + static double err_max = 0.0; + double f0 = (double) *pF0 / ( 1 << 10 ); + double f0_32 = (double) *pF0_32 / ( 1 << 26 ); + double err = fabs( f0 - f0_32 ); + err_max = fmax( err_max, err ); + printf( "# GetF0 frame=%d *F0_32=0x%08x (%5.10f) *F0=0x%04x (%5.10f) err_max=%5.10f err=%5.10f, tmp_32=%d, tmp=%d \n", + frame, *pF0_32, f0_32, *pF0, f0, err_max, err, tmp_32, tmp); +#endif + tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) { @@ -583,32 +585,19 @@ static void GetF0( tmp = nSamples; } #ifdef FIX_ISSUE_1966 - double k2 = ((Word32)tmp<<15) / (*pF0_32*pow(2.,-16+5)); - Word32 nTotalHarmonics_32 = double_to_q31_with_exp(k2, &tmp_32); -#endif - BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); -#ifdef DEBUG_ISSUE_1966 - if (tmp != tmp_32) printf("tmp=%d tmp_32=%d\n", tmp,tmp_32 ); - assert( tmp == tmp_32 ); -#endif -#ifdef DEBUG_ISSUE_1966__ - printf("# frame=%d k2=%f fx16=%f, \n", - frame, k2, nTotalHarmonics*pow(2.,-15+tmp ) ); -#endif + BASOP_Util_Divide_MantExp( tmp, 15, extract_h( *pF0_32 ), 5, &nTotalHarmonics, &tmp ); nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); -#ifdef FIX_ISSUE_1966 - nTotalHarmonics_32 = L_shl( nTotalHarmonics_32, L_sub( tmp_32, 31 ) ); -#ifdef DEBUG_ISSUE_1966___ - if (nTotalHarmonics != nTotalHarmonics_32) - printf("# nTotalHarmonics=%d nTotalHarmonics_32=%d\n", - nTotalHarmonics, nTotalHarmonics_32 ); -#endif -#endif + /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ + findStrongestHarmonics( nSamples, powerSpectrum, extract_h( *pF0_32 ), nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); + CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0, pF0_32 ); +#else + BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); + nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); - CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0 ); +#endif } ELSE { @@ -616,6 +605,12 @@ static void GetF0( move16(); *pF0 = 0; *pOrigF0 = 0; +#ifdef FIX_ISSUE_1966 + move32(); + move32(); + *pF0_32 = 0; + *pOrigF0_32 = 0; +#endif } return; @@ -711,10 +706,18 @@ static void findStrongestHarmonics( static void CorrectF0( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ - Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ +#ifdef FIX_ISSUE_1966 + Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ + Word32 /*long*/ *pF0_32 ) /*I/O - Q10+16 range: {0}, [4..18) */ +#else + Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ +#endif { Word16 /*short*/ i; Word16 /*short*/ F0; +#ifdef FIX_ISSUE_1966 + Word32 F0_32; +#endif Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ Word16 /*short*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; /*Q0*/ @@ -729,10 +732,26 @@ static void CorrectF0( } F0 = *pF0; /*Q10*/ +#ifdef FIX_ISSUE_1966 + F0_32 = *pF0_32; +#endif + +#ifdef DEBUG_ISSUE_1966 + /* Condition should be identical for 16 or 32 version */ + if ( ( F0 == 0 ) && ( F0_32 != 0 ) ) + printf("CorrectF0: F0 (0x%04X) != F0_32 (0x%08X)\n", F0, F0_32); +#endif test(); +#ifdef FIX_ISSUE_1966 + IF( F0_32 > 0 && nHarmonics != 0 ) +#else IF( F0 > 0 && nHarmonics != 0 ) +#endif { +#ifdef DEBUG_ISSUE_1966 + printf( "CorrectF0: - start - F0 (0x%04X), F0_32 (0x%08X)\n", F0, F0_32 ); +#endif tmp = sub( nHarmonics, 1 ); FOR( i = 0; i < tmp; i++ ) { @@ -836,11 +855,24 @@ static void CorrectF0( { /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ +#ifdef FIX_ISSUE_1966 + F0_32 = L_shl_sat( Mpy_32_16_1( F0_32 /*Q10+16*/, iMostCommonDiff /*Q0*/ ), 15 ); /*Q10+16*/ +#endif +#ifdef DEBUG_ISSUE_1966 + printf("CorrectF0: A F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32,F0, frame ); +#endif } ELSE { +#ifdef FIX_ISSUE_1966 + F0_32 = 0; + move32(); +#endif F0 = 0; move16(); +#ifdef DEBUG_ISSUE_1966 + printf( "CorrectF0: B F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); +#endif } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ @@ -851,13 +883,27 @@ static void CorrectF0( if ( ( GT_16( iMostCommonDiff, 1 ) ) || ( LT_16( nMostCommonDiff, 3 ) ) ) { /* Not enough peaks at the same distance => don't use the pitch. */ +#ifdef FIX_ISSUE_1966 + F0_32 = 0; + move32(); +#endif F0 = 0; move16(); +#ifdef DEBUG_ISSUE_1966 + printf( "CorrectF0: C F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); +#endif } } +#ifdef FIX_ISSUE_1966 + *pF0_32 = F0_32; + move32(); +#endif *pF0 = F0; move16(); } +#ifdef DEBUG_ISSUE_1966 + printf( "CorrectF0: D F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); +#endif return; } @@ -937,15 +983,15 @@ static void modifyThresholds( FOR( i = 1; i <= nHarmonics; i++ ) { modifyThreshold( i, origF0, -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 origF0_32, #endif - 717 /*0.7f Q10*/ /*0.7f in Q10*/, -#ifdef DEBUG_ISSUE_1966 - 717 * 0x10000, + 717 /*0.7f in Q10*/, +#ifdef FIX_ISSUE_1966 + 46976205 /*0.7f in Q10+16*/ , #endif thresholdModification -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 , thresholdModification_32 #endif @@ -963,15 +1009,15 @@ static void modifyThresholds( FOR( i = tmp; i > 0; i-- ) { modifyThreshold( i, origF0, -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 origF0_32, #endif - 358 /*0.35f Q10*/, -#ifdef DEBUG_ISSUE_1966 - 358 * 0x10000, + 358 /*0.35f in Q10*/, +#ifdef FIX_ISSUE_1966 + 23488102 /*0.35 in Q10+16*/, #endif thresholdModification -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 , thresholdModification_32 #endif @@ -980,15 +1026,15 @@ static void modifyThresholds( FOR( i = 1; i <= nHarmonics; i++ ) { modifyThreshold( i, F0, -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 origF0_32, #endif 358 /*0.35f Q10*/, -#ifdef DEBUG_ISSUE_1966 - 358 * 0x10000, +#ifdef FIX_ISSUE_1966 + 23488102 /*0.35 in Q10+16*/, #endif thresholdModification -#ifdef DEBUG_ISSUE_1966 +#ifdef FIX_ISSUE_1966 , thresholdModification_32 #endif -- GitLab From 216bf478736bfa9c933e608878a8b9689aa50c44 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 29 Apr 2026 22:04:38 +0200 Subject: [PATCH 05/19] fix clang-format issue --- lib_dec/TonalComponentDetection_fx.c | 148 ++++++++++++++------------- lib_dec/er_util_fx.c | 6 +- lib_dec/ivas_mdct_core_dec_fx.c | 5 +- lib_dec/tonalMDCTconcealment_fx.c | 20 ++-- 4 files changed, 92 insertions(+), 87 deletions(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index 702a02e9c..0f4614254 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,8 +12,8 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -//#define FIX_ISSUE_1966 -//#define DEBUG_ISSUE_1966 +// #define FIX_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef FIX_ISSUE_1966 #include #include @@ -35,11 +35,12 @@ static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 #endif static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, #ifdef FIX_ISSUE_1966 - Word32 *const pOrigF0_32, + Word32 *const pOrigF0_32, #endif - Word16 *const pF0 + Word16 *const pF0 #ifdef FIX_ISSUE_1966 - , Word32 *const pF0_32 + , + Word32 *const pF0_32 #endif ); static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); @@ -49,8 +50,7 @@ static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); #endif #ifdef FIX_ISSUE_1966 -static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, - Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum ); +static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum ); #else static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); #endif @@ -83,24 +83,23 @@ static void modifyThresholds( Word16 F0, #endif ); #ifdef FIX_ISSUE_1966 -static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, - Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32 ); +static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32 ); #else static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); #endif #ifdef FIX_ISSUE_1966 -static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, - Word16 F0, Word32 F0_32, Word16 *thresholdModification, Word32 *thresholdModification32, Word16 element_mode ); +static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word32 F0_32, Word16 *thresholdModification, Word32 *thresholdModification32, Word16 element_mode ); #else 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 ); #endif #ifdef FIX_ISSUE_1966 -static inline int32_t double_to_q31_with_exp(double x, int *out_exp) { +static inline int32_t double_to_q31_with_exp( double x, int *out_exp ) +{ // Zerlege x in Mantisse und Exponent: x = m * 2^e, m in [0.5, 1) oder (-1, -0.5] int e; - double m = frexp(x, &e); // x = m * 2^e, mit |m| in (0.5, 1] + double m = frexp( x, &e ); // x = m * 2^e, mit |m| in (0.5, 1] // Normalisiere so, dass |m| in [0.5, 1). Wir möchten später m in [-1,1) skalieren. // Wir wählen hier eine Darstellung mit Mantisse in [-1, 1). @@ -111,27 +110,31 @@ static inline int32_t double_to_q31_with_exp(double x, int *out_exp) { // In Q31 kann Mantisse m_q31 = round(m * 2^31). // Grenzen beachten: |m| < 1, also m_q31 liegt in (-2^31, 2^31-1). Wir saturieren ggf. - double scaled = m * (double)(1ULL << 31); // 2^31 + double scaled = m * (double) ( 1ULL << 31 ); // 2^31 // Rundung - if (scaled >= 0.0) + if ( scaled >= 0.0 ) scaled += 0.5; else scaled -= 0.5; // Saturation in int32_t - if (scaled > (double)INT32_MAX) scaled = (double)INT32_MAX; - if (scaled < (double)INT32_MIN) scaled = (double)INT32_MIN; + if ( scaled > (double) INT32_MAX ) + scaled = (double) INT32_MAX; + if ( scaled < (double) INT32_MIN ) + scaled = (double) INT32_MIN; - int32_t m_q31 = (int32_t)scaled; + int32_t m_q31 = (int32_t) scaled; - if (out_exp) *out_exp = e; + if ( out_exp ) + *out_exp = e; return m_q31; } // Optionaler Helper: Mantisse aus Q31 zurück zu double (nur zur Überprüfung) -static inline double q31_to_double(int32_t q31) { +static inline double q31_to_double( int32_t q31 ) +{ // q31 → double in [-1, 1) - return ((double)q31) / (double)(1ULL << 31); + return ( (double) q31 ) / (double) ( 1ULL << 31 ); } #endif @@ -176,7 +179,7 @@ void DetectTonalComponents_fx( Word32 sns_int_scf_fx[FDNS_NPTS]; /*Q16*/ Word16 q_pScaledMdctSpectrum; #ifdef DEBUG_ISSUE_1966 - printf("Calling DetectTonalComponents in frame=%d\n", frame); + printf( "Calling DetectTonalComponents in frame=%d\n", frame ); #endif set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); @@ -243,15 +246,15 @@ void DetectTonalComponents_fx( /* Refine peak candidates using the pitch information */ #ifdef FIX_ISSUE_1966 - RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, &F0_32, - thresholdModification, thresholdModification32 ); + RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, &F0_32, + thresholdModification, thresholdModification32 ); #else RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); #endif /* Find peaks in the second last frame */ #ifdef FIX_ISSUE_1966 - findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, + findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, F0_32, thresholdModification, thresholdModification32, element_mode ); #else findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); @@ -423,7 +426,7 @@ static void getEnvelope( const Word32 *powerSpec, /*i : powerSpec_exp */ Word16 F0, /*i : 5Q10*/ #ifdef FIX_ISSUE_1966 - Word32 F0_32, /*i : 5Q10+Q16*/ + Word32 F0_32, /*i : 5Q10+Q16*/ #endif Word32 *envelope, /*o : powerSpec_exp + LEVEL_EXP Q28*/ Word32 *smoothedSpectrum /*o : powerSpec_exp + LEVEL_EXP Q28*/ @@ -527,9 +530,10 @@ static void GetF0( #ifdef FIX_ISSUE_1966 Word32 *const pOrigF0_32, #endif - Word16 /*short*/ *const pF0 /*o - Q10*/ + Word16 /*short*/ *const pF0 /*o - Q10*/ #ifdef FIX_ISSUE_1966 - , Word32 *const pF0_32 + , + Word32 *const pF0_32 #endif ) { @@ -553,16 +557,16 @@ static void GetF0( /**pF0 = nSamplesCore/tmpPitchLag;*/ BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ - *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ + *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ move16(); *pOrigF0 = *pF0; /*Q10*/ move16(); #ifdef FIX_ISSUE_1966 Word16 tmp_32 = 0; - Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton(L_shl(nSamplesCore, Q16), tmpPitchLag, &tmp_32); - if (tmp_32 != Q16) - F0_32 = L_shl(F0_32, tmp_32 - Q16); + Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton( L_shl( nSamplesCore, Q16 ), tmpPitchLag, &tmp_32 ); + if ( tmp_32 != Q16 ) + F0_32 = L_shl( F0_32, tmp_32 - Q16 ); *pF0_32 = F0_32; move32(); *pOrigF0_32 = *pF0_32; /*Q26*/ @@ -575,7 +579,7 @@ static void GetF0( double err = fabs( f0 - f0_32 ); err_max = fmax( err_max, err ); printf( "# GetF0 frame=%d *F0_32=0x%08x (%5.10f) *F0=0x%04x (%5.10f) err_max=%5.10f err=%5.10f, tmp_32=%d, tmp=%d \n", - frame, *pF0_32, f0_32, *pF0, f0, err_max, err, tmp_32, tmp); + frame, *pF0_32, f0_32, *pF0, f0, err_max, err, tmp_32, tmp ); #endif tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; @@ -707,8 +711,8 @@ static void CorrectF0( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ #ifdef FIX_ISSUE_1966 - Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ - Word32 /*long*/ *pF0_32 ) /*I/O - Q10+16 range: {0}, [4..18) */ + Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ + Word32 /*long*/ *pF0_32 ) /*I/O - Q10+16 range: {0}, [4..18) */ #else Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ #endif @@ -739,7 +743,7 @@ static void CorrectF0( #ifdef DEBUG_ISSUE_1966 /* Condition should be identical for 16 or 32 version */ if ( ( F0 == 0 ) && ( F0_32 != 0 ) ) - printf("CorrectF0: F0 (0x%04X) != F0_32 (0x%08X)\n", F0, F0_32); + printf( "CorrectF0: F0 (0x%04X) != F0_32 (0x%08X)\n", F0, F0_32 ); #endif test(); @@ -859,7 +863,7 @@ static void CorrectF0( F0_32 = L_shl_sat( Mpy_32_16_1( F0_32 /*Q10+16*/, iMostCommonDiff /*Q0*/ ), 15 ); /*Q10+16*/ #endif #ifdef DEBUG_ISSUE_1966 - printf("CorrectF0: A F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32,F0, frame ); + printf( "CorrectF0: A F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); #endif } ELSE @@ -910,21 +914,21 @@ static void CorrectF0( static void modifyThreshold( - Word16 /*short*/ i, /*I - Q0 */ - Word16 /*short*/ F0, /*I - Q10*/ + Word16 /*short*/ i, /*I - Q0 */ + Word16 /*short*/ F0, /*I - Q10*/ #ifdef FIX_ISSUE_1966 - Word32 F0_32, /*I - Qi26*/ + Word32 F0_32, /*I - Qi26*/ #endif - Word16 /*short*/ threshold, /*I - Q10*/ + Word16 /*short*/ threshold, /*I - Q10*/ #ifdef FIX_ISSUE_1966 - Word32 threshold_32, /*I - Q26*/ + Word32 threshold_32, /*I - Q26*/ #endif - Word16 * /*short*/ thresholdModification /*I - Q10*/ + Word16 * /*short*/ thresholdModification /*I - Q10*/ #ifdef FIX_ISSUE_1966 , Word32 * /*short*/ thresholdModification_32 #endif -) /*I/O - Q10*/ + ) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; @@ -943,12 +947,12 @@ static void modifyThreshold( move16(); thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ #ifdef DEBUG_ISSUE_1966 - if (frame == 1384) - printf("modifyThreshold: [%d] %15.15f %15.15f %15.15f F0 %15.15f\n", k - 1, - (double) thresholdModification[k-1] / (1 << 10), - (double) thresholdModification[k+0] / (1 << 10), - (double) thresholdModification[k+1] / (1 << 10), - (double) F0 / (1 << 10) ); + if ( frame == 1384 ) + printf( "modifyThreshold: [%d] %15.15f %15.15f %15.15f F0 %15.15f\n", k - 1, + (double) thresholdModification[k - 1] / ( 1 << 10 ), + (double) thresholdModification[k + 0] / ( 1 << 10 ), + (double) thresholdModification[k + 1] / ( 1 << 10 ), + (double) F0 / ( 1 << 10 ) ); #endif return; @@ -956,20 +960,20 @@ static void modifyThreshold( static void modifyThresholds( - Word16 /*short*/ F0, /*I - Q10*/ + Word16 /*short*/ F0, /*I - Q10*/ #ifdef FIX_ISSUE_1966 - Word32 F0_32, /*I - Qi26*/ + Word32 F0_32, /*I - Qi26*/ #endif - Word16 /*short*/ origF0, /*I - Q10*/ + Word16 /*short*/ origF0, /*I - Q10*/ #ifdef FIX_ISSUE_1966 - Word32 origF0_32, /*I - Qi26*/ + Word32 origF0_32, /*I - Qi26*/ #endif Word16 * /*short*/ thresholdModification #ifdef FIX_ISSUE_1966 , Word32 * /*short*/ thresholdModification_32 #endif -) /*I/O - Q10*/ + ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; @@ -988,14 +992,14 @@ static void modifyThresholds( #endif 717 /*0.7f in Q10*/, #ifdef FIX_ISSUE_1966 - 46976205 /*0.7f in Q10+16*/ , + 46976205 /*0.7f in Q10+16*/, #endif thresholdModification #ifdef FIX_ISSUE_1966 , thresholdModification_32 #endif - ); + ); } } IF( F0 > 0 ) @@ -1055,7 +1059,7 @@ static void findCandidates( #ifdef FIX_ISSUE_1966 Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ #endif - Word16 floorPowerSpectrum /* i : lower limit for power spectrum bins Q0*/ + Word16 floorPowerSpectrum /* i : lower limit for power spectrum bins Q0*/ ) { Word32 powerSpectrum[L_FRAME_MAX]; @@ -1077,7 +1081,7 @@ static void findCandidates( set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ #ifdef FIX_ISSUE_1966 - set32_fx( thresholdModificationNew32, (UNREACHABLE_THRESHOLD) << 16, nSamples ); /*Q10+Q16*/ + set32_fx( thresholdModificationNew32, ( UNREACHABLE_THRESHOLD ) << 16, nSamples ); /*Q10+Q16*/ #endif @@ -1208,15 +1212,15 @@ static void findTonalComponents_fx( Word16 nSamples, /* IN */ const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, - Word16 F0, /* IN */ + Word16 F0, /* IN */ #ifdef FIX_ISSUE_1966 - Word32 F0_32, /* IN */ + Word32 F0_32, /* IN */ #endif Word16 *thresholdModification, /* IN Q10*/ #ifdef FIX_ISSUE_1966 Word32 *thresholdModification32, /* IN Q10+Q16*/ #endif - Word16 element_mode ) /* IN */ + Word16 element_mode ) /* IN */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -1227,11 +1231,11 @@ static void findTonalComponents_fx( Word16 tmp_loop1, tmp_loop2, tmp_loop3; #ifdef DEBUG_ISSUE_1966 - if (frame == 1384) + if ( frame == 1384 ) { - for (j = 0; j < nSamples; j++) + for ( j = 0; j < nSamples; j++ ) { - printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) (1 << 10) ); + printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); } } #endif @@ -1377,7 +1381,7 @@ static void findTonalComponents_fx( move16(); #ifdef DEBUG_ISSUE_1966 if ( frame == 1384 ) - printf( "nrOfFIS=%d k=%d\n", nrOfFIS , k); + printf( "nrOfFIS=%d k=%d\n", nrOfFIS, k ); #endif IF( EQ_16( nrOfFIS, MAX_NUMBER_OF_IDX ) ) @@ -1406,11 +1410,12 @@ static void RefineThresholdsUsingPitch_fx( const Word32 currentPitchLag, /*Qx*/ Word16 *pF0, /*Q10*/ #ifdef FIX_ISSUE_1966 - Word32 *pF0_32, /*Q10+Q16*/ + Word32 *pF0_32, /*Q10+Q16*/ #endif Word16 *thresholdModification /*Q10*/ #ifdef FIX_ISSUE_1966 - , Word32 *thresholdModification32 /*Q10+Q16*/ + , + Word32 *thresholdModification32 /*Q10+Q16*/ #endif ) { @@ -1435,11 +1440,12 @@ static void RefineThresholdsUsingPitch_fx( { GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, #ifdef FIX_ISSUE_1966 - &origF0_32, + &origF0_32, #endif - pF0 + pF0 #ifdef FIX_ISSUE_1966 - ,pF0_32 + , + pF0_32 #endif ); diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 9c5b13242..e4670d965 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -11,7 +11,7 @@ #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -382,7 +382,7 @@ Word16 GetPLCModeDecision_fx( hTcxDec = st->hTcxDec; #ifdef DEBUG_ISSUE_1966 - printf("Calling GetPLCModeDecision in frame=%d\n", frame); + printf( "Calling GetPLCModeDecision in frame=%d\n", frame ); #endif IF( EQ_16( st->flagGuidedAcelp, 1 ) ) @@ -475,7 +475,7 @@ Word16 GetPLCModeDecision_fx( test(); test(); #ifdef DEBUG_ISSUE_1966 - printf("-->pitch=%f numIndices=%2d\n", (double) pitch / (double) (1 << 16), numIndices); + printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); #endif IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 9961fd771..f6bccc0cb 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -40,7 +40,7 @@ #include "basop_proto_func.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -1521,7 +1521,7 @@ void ivas_mdct_core_tns_ns_fx( #endif #ifdef DEBUG_ISSUE_1966 - printf("Calling ivas_mdct_core_tns_ns in frame=%d\n", frame); + printf( "Calling ivas_mdct_core_tns_ns in frame=%d\n", frame ); #endif /* Initializations */ @@ -1604,7 +1604,6 @@ void ivas_mdct_core_tns_ns_fx( #ifdef DEBUG_ISSUE_1966 printf( "->ch=%d tonal_mdct_plc_active=%d F2\n", ch, st->tonal_mdct_plc_active ); #endif - } /* nothing to do for missing LFE */ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 64331df0e..3502e562d 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -13,7 +13,7 @@ #include "stat_com.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -524,8 +524,8 @@ void TonalMDCTConceal_UpdateState_fx( { Word8 newBlockIsValid; #ifdef DEBUG_ISSUE_1966 - printf("Calling TonalMDCTConceal_UpdateState in frame=%d: ns=%d pl=%f bB=%d tCA=%d\n", - frame, nNewSamples, (double) pitchLag / (double) (1 << 16), badBlock, tonalConcealmentActive); + printf( "Calling TonalMDCTConceal_UpdateState in frame=%d: ns=%d pl=%f bB=%d tCA=%d\n", + frame, nNewSamples, (double) pitchLag / (double) ( 1 << 16 ), badBlock, tonalConcealmentActive ); #endif assert( !( !badBlock && tonalConcealmentActive ) ); @@ -651,7 +651,7 @@ static void FindPhaseDifferences( #else if ( EQ_16( s_and( k, 3 ), 1 ) ) { - phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; + phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; move16(); } if ( EQ_16( s_and( k, 3 ), 2 ) ) @@ -690,7 +690,7 @@ static void FindPhaseDifferences( } if ( EQ_16( s_and( k, 3 ), 2 ) ) { - phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; + phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; move16(); } if ( EQ_16( s_and( k, 3 ), 3 ) ) @@ -767,11 +767,11 @@ static void FindPhaseDifferences( #endif } } -#ifdef DEBUG_ISSUE_1966 +#ifdef DEBUG_ISSUE_1966 printf( "phaseDiff[%3d]=%15.15f frac=%15.15f a_way=%d\n l/r=%15.15f k=%d\n", - i, - (double) phaseDiff[i] / (double) (1 << 12), - ( a_way == 3 ) ? (double) L_mult(fractional, 28672) / (double) (1 << 27) : 0.f, + i, + (double) phaseDiff[i] / (double) ( 1 << 12 ), + ( a_way == 3 ) ? (double) L_mult( fractional, 28672 ) / (double) ( 1 << 27 ) : 0.f, a_way, (double) powerSpectrum[k - 1] / (double) powerSpectrum[k + 1], hTonalMDCTConc->pTCI->indexOfTonalPeak[i] ); @@ -1202,7 +1202,7 @@ void TonalMDCTConceal_Detect_fx( #ifdef DEBUG_ISSUE_1966 printf( "Using TonalMDCTConceal_Detect in path=%d\n", det_way ); #endif - + *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); -- GitLab From cb73ed29ed2aacd356ca432c85140f2c373d5dc7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 30 Apr 2026 17:55:32 +0200 Subject: [PATCH 06/19] correct phase setting with 4 quadrants - active, when macro FIX_ISSUE_1966 is active --- lib_dec/tonalMDCTconcealment_fx.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) mode change 100644 => 100755 lib_dec/tonalMDCTconcealment_fx.c diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c old mode 100644 new mode 100755 index 3502e562d..6174429ce --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -13,7 +13,7 @@ #include "stat_com.h" #include "ivas_prot_fx.h" -// #define DEBUG_ISSUE_1966 +//#define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -642,7 +642,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); -#if 0 +#ifndef FIX_ISSUE_1966 if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; @@ -676,7 +676,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); -#if 0 +#ifndef FIX_ISSUE_1966 if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ @@ -849,7 +849,7 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( } #ifdef DEBUG_ISSUE_1966 - printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + //printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, @@ -868,7 +868,7 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #ifdef DEBUG_ISSUE_1966 - printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + //printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); @@ -1022,7 +1022,7 @@ void TonalMDCTConceal_Detect_fx( Word32 sns_int_scf_fx[FDNS_NPTS]; #ifdef DEBUG_ISSUE_1966 Word32 det_way = 0; - printf( "Calling TonalMDCTConceal_Detect in frame=%d *numIndices=%d ->numIndexes=%d\n", frame, *numIndices, hTonalMDCTConc->pTCI->numIndexes ); + printf( "Calling TonalMDCTConceal_Detect in frame=%d\n", frame); #endif set32_fx( sns_int_scf_fx, 0, FDNS_NPTS ); @@ -1163,7 +1163,7 @@ void TonalMDCTConceal_Detect_fx( powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } #ifdef DEBUG_ISSUE_1966 - printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + //printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, @@ -1184,7 +1184,7 @@ void TonalMDCTConceal_Detect_fx( hTonalMDCTConc->nSamplesCore, extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ #ifdef DEBUG_ISSUE_1966 - printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + //printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif } } -- GitLab From edbd969239468287f2781bf54889029eadf932a5 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 30 Apr 2026 18:02:15 +0200 Subject: [PATCH 07/19] added F0_32 in 32-bit to existing code (F0, 16 bit), added lots of debug prints, all inactive, 32-bit version is active, if FIX_ISSUE_1966 is active --- lib_dec/TonalComponentDetection_fx.c | 129 ++++++++++++++++++++++++--- lib_dec/er_util_fx.c | 6 +- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 3 files changed, 122 insertions(+), 15 deletions(-) mode change 100644 => 100755 lib_dec/TonalComponentDetection_fx.c mode change 100644 => 100755 lib_dec/er_util_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100644 new mode 100755 index 0f4614254..46b4cc042 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,8 +12,8 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -// #define FIX_ISSUE_1966 -// #define DEBUG_ISSUE_1966 +//#define FIX_ISSUE_1966 +//#define DEBUG_ISSUE_1966 #ifdef FIX_ISSUE_1966 #include #include @@ -460,6 +460,37 @@ static void getEnvelope( nFilterLength = s_or( 1, shr( F0, 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ move16(); } +#ifdef DEBUG_ISSUE_1966 + printf("getEnvelope in frame=%d: F0=0x%04X nFilterLength=%d\n", frame, F0, nFilterLength); +#endif +#ifdef FIX_ISSUE_1966 + IF( F0_32 == 0 ) + { + nFilterLength = 15; /*Q0*/ + move16(); + } + ELSE IF( F0_32 <= (10240 << 16) /*10.0f Q10*/ ) + { + nFilterLength = 11; /*Q0*/ + move16(); + } + ELSE IF( F0_32 >= (22528 << 16) /*22.0f Q10*/ ) + { + /* For F0 >= 22 peak is isolated well enough with the filter length of 23. + This case is however not triggered due to the limit of pit_min, + but the line is left for security reasons. */ + nFilterLength = 23; /*Q0*/ + move16(); + } + ELSE + { + nFilterLength = s_or( 1, shr( extract_h(F0_32), 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ + move16(); + } +#ifdef DEBUG_ISSUE_1966 + printf( "getEnvelope in frame=%d: F0_32=0x%08X nFilterLength=%d\n", frame, F0_32, nFilterLength ); +#endif +#endif nHalfFilterLength = shr( nFilterLength, 1 ); @@ -565,8 +596,7 @@ static void GetF0( #ifdef FIX_ISSUE_1966 Word16 tmp_32 = 0; Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton( L_shl( nSamplesCore, Q16 ), tmpPitchLag, &tmp_32 ); - if ( tmp_32 != Q16 ) - F0_32 = L_shl( F0_32, tmp_32 - Q16 ); + F0_32 = L_shl( F0_32, tmp_32 - Q16 ); *pF0_32 = F0_32; move32(); *pOrigF0_32 = *pF0_32; /*Q26*/ @@ -934,6 +964,9 @@ static void modifyThreshold( Word16 fractional /*Q15*/; Word16 k /*Q0*/; Word16 twoTimesFract /*Q10*/; +#ifdef FIX_ISSUE_1966 + Word32 L_twoTimesFract /*Q10+16*/; +#endif harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ k = extract_h( harmonic ); /*Q0*/ @@ -947,12 +980,40 @@ static void modifyThreshold( move16(); thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ #ifdef DEBUG_ISSUE_1966 - if ( frame == 1384 ) - printf( "modifyThreshold: [%d] %15.15f %15.15f %15.15f F0 %15.15f\n", k - 1, + //if ( frame == 1384 ) +#if 0 + printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0 %15.15f fract %15.15f\n", k - 1, (double) thresholdModification[k - 1] / ( 1 << 10 ), (double) thresholdModification[k + 0] / ( 1 << 10 ), (double) thresholdModification[k + 1] / ( 1 << 10 ), - (double) F0 / ( 1 << 10 ) ); + (double) F0 / ( 1 << 10 ), + (double) twoTimesFract / (1 << 10) ); +#endif +#endif + +#ifdef FIX_ISSUE_1966 + harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) ); /*Q0 * Q10 = 15Q16*/ + k = extract_h( harmonic ); /*Q0*/ + fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ + L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + + move32(); + thresholdModification_32[k] = threshold_32;/*Q10+16*/ + move32(); + thresholdModification_32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/ + move32(); + thresholdModification_32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ +#ifdef DEBUG_ISSUE_1966 + //if ( frame == 1384 ) + if (( thresholdModification_32[k + 0] != (16 << 26) ) && ( thresholdModification[k + 0] != (16 << 10) ) ) + printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0_32 %15.15f fract %15.15f diff=%15.15f\n", k - 1, + (double) thresholdModification_32[k - 1] / ( 1 << 26 ), + (double) thresholdModification_32[k + 0] / ( 1 << 26 ), + (double) thresholdModification_32[k + 1] / ( 1 << 26 ), + (double) F0_32 / ( 1 << 26 ), + (double) L_twoTimesFract / ( 1 << 26 ), + (double) thresholdModification_32[k + 0] / ( 1 << 26 ) - (double) thresholdModification[k + 0] / ( 1 << 10 ) ); +#endif #endif return; @@ -1031,7 +1092,7 @@ static void modifyThresholds( { modifyThreshold( i, F0, #ifdef FIX_ISSUE_1966 - origF0_32, + F0_32, #endif 358 /*0.35f Q10*/, #ifdef FIX_ISSUE_1966 @@ -1231,13 +1292,21 @@ static void findTonalComponents_fx( Word16 tmp_loop1, tmp_loop2, tmp_loop3; #ifdef DEBUG_ISSUE_1966 - if ( frame == 1384 ) - { + //if ( frame == 1384 ) + //{ +printf( "findTonalComponents in frame %d\n", frame); for ( j = 0; j < nSamples; j++ ) { +#ifdef FIX_ISSUE_1966 + if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) + printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), + (double) thresholdModification32[j] / (double) ( 1 << 26 ), + ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); +#else printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); +#endif } - } + //} #endif #ifdef FIX_ISSUE_1966 @@ -1270,6 +1339,21 @@ static void findTonalComponents_fx( 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 ) ); flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); +#ifdef DEBUG_ISSUE_1966 + printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), + mult_32, mult_exp ); +#endif +#ifdef FIX_ISSUE_1966 + mult_64 = W_mult_32_32( envelope[k], thresholdModification32[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10+16 + lshift = W_norm( mult_64 ); + mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 + mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10+16, lshift ) ), 31 ) ); + flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); +#ifdef DEBUG_ISSUE_1966 + printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), + mult_32, mult_exp ); +#endif +#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 */ @@ -1426,6 +1510,25 @@ static void RefineThresholdsUsingPitch_fx( #endif Word32 L_tmp; + +#ifdef DEBUG_ISSUE_1966 + // if ( frame == 1384 ) + //{ + printf( "RefineThresholdsUsingPitch in frame %d\n", frame ); + for ( int j = 0; j < nSamples; j++ ) + { +#ifdef FIX_ISSUE_1966 + if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) + printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), + (double) thresholdModification32[j] / (double) ( 1 << 26 ), + ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); +#else + printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); +#endif + } + //} +#endif + /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ pitchIsStable = 0; move16(); @@ -1468,6 +1571,10 @@ static void RefineThresholdsUsingPitch_fx( { *pF0 = 0; move16(); +#ifdef FIX_ISSUE_1966 + *pF0_32 = 0; + move32(); +#endif } return; diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c old mode 100644 new mode 100755 index e4670d965..5f538bf0a --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -11,7 +11,7 @@ #include "ivas_prot_fx.h" -// #define DEBUG_ISSUE_1966 +//#define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -420,7 +420,7 @@ Word16 GetPLCModeDecision_fx( st->tonal_mdct_plc_active = 0; move16(); #ifdef DEBUG_ISSUE_1966 - printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); + //printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); #endif } ELSE @@ -475,7 +475,7 @@ Word16 GetPLCModeDecision_fx( test(); test(); #ifdef DEBUG_ISSUE_1966 - printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); + //printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); #endif IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index f6bccc0cb..a734680fa 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -40,7 +40,7 @@ #include "basop_proto_func.h" #include "ivas_prot_fx.h" -// #define DEBUG_ISSUE_1966 +//#define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; -- GitLab From 26c69fe497547fef36b6d13699f15efb5a531f74 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Thu, 30 Apr 2026 18:17:07 +0200 Subject: [PATCH 08/19] clang-format --- lib_dec/TonalComponentDetection_fx.c | 52 ++++++++++++++-------------- lib_dec/er_util_fx.c | 6 ++-- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 14 ++++---- 4 files changed, 37 insertions(+), 37 deletions(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c mode change 100755 => 100644 lib_dec/er_util_fx.c mode change 100755 => 100644 lib_dec/tonalMDCTconcealment_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index 46b4cc042..d98b0b79c --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,8 +12,8 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -//#define FIX_ISSUE_1966 -//#define DEBUG_ISSUE_1966 +// #define FIX_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef FIX_ISSUE_1966 #include #include @@ -461,7 +461,7 @@ static void getEnvelope( move16(); } #ifdef DEBUG_ISSUE_1966 - printf("getEnvelope in frame=%d: F0=0x%04X nFilterLength=%d\n", frame, F0, nFilterLength); + printf( "getEnvelope in frame=%d: F0=0x%04X nFilterLength=%d\n", frame, F0, nFilterLength ); #endif #ifdef FIX_ISSUE_1966 IF( F0_32 == 0 ) @@ -469,12 +469,12 @@ static void getEnvelope( nFilterLength = 15; /*Q0*/ move16(); } - ELSE IF( F0_32 <= (10240 << 16) /*10.0f Q10*/ ) + ELSE IF( F0_32 <= ( 10240 << 16 ) /*10.0f Q10*/ ) { nFilterLength = 11; /*Q0*/ move16(); } - ELSE IF( F0_32 >= (22528 << 16) /*22.0f Q10*/ ) + ELSE IF( F0_32 >= ( 22528 << 16 ) /*22.0f Q10*/ ) { /* For F0 >= 22 peak is isolated well enough with the filter length of 23. This case is however not triggered due to the limit of pit_min, @@ -484,7 +484,7 @@ static void getEnvelope( } ELSE { - nFilterLength = s_or( 1, shr( extract_h(F0_32), 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ + nFilterLength = s_or( 1, shr( extract_h( F0_32 ), 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ move16(); } #ifdef DEBUG_ISSUE_1966 @@ -980,7 +980,7 @@ static void modifyThreshold( move16(); thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ #ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) + // if ( frame == 1384 ) #if 0 printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0 %15.15f fract %15.15f\n", k - 1, (double) thresholdModification[k - 1] / ( 1 << 10 ), @@ -995,17 +995,17 @@ static void modifyThreshold( harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) ); /*Q0 * Q10 = 15Q16*/ k = extract_h( harmonic ); /*Q0*/ fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ - L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ move32(); - thresholdModification_32[k] = threshold_32;/*Q10+16*/ + thresholdModification_32[k] = threshold_32; /*Q10+16*/ move32(); thresholdModification_32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/ move32(); thresholdModification_32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ #ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) - if (( thresholdModification_32[k + 0] != (16 << 26) ) && ( thresholdModification[k + 0] != (16 << 10) ) ) + // if ( frame == 1384 ) + if ( ( thresholdModification_32[k + 0] != ( 16 << 26 ) ) && ( thresholdModification[k + 0] != ( 16 << 10 ) ) ) printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0_32 %15.15f fract %15.15f diff=%15.15f\n", k - 1, (double) thresholdModification_32[k - 1] / ( 1 << 26 ), (double) thresholdModification_32[k + 0] / ( 1 << 26 ), @@ -1292,20 +1292,20 @@ static void findTonalComponents_fx( Word16 tmp_loop1, tmp_loop2, tmp_loop3; #ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) + // if ( frame == 1384 ) //{ -printf( "findTonalComponents in frame %d\n", frame); - for ( j = 0; j < nSamples; j++ ) - { + printf( "findTonalComponents in frame %d\n", frame ); + for ( j = 0; j < nSamples; j++ ) + { #ifdef FIX_ISSUE_1966 - if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) + if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), - (double) thresholdModification32[j] / (double) ( 1 << 26 ), + (double) thresholdModification32[j] / (double) ( 1 << 26 ), ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); #else - printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); + printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); #endif - } + } //} #endif @@ -1340,18 +1340,18 @@ printf( "findTonalComponents in frame %d\n", frame); Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); #ifdef DEBUG_ISSUE_1966 - printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), - mult_32, mult_exp ); + printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), + mult_32, mult_exp ); #endif #ifdef FIX_ISSUE_1966 mult_64 = W_mult_32_32( envelope[k], thresholdModification32[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10+16 lshift = W_norm( mult_64 ); mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 - mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10+16, lshift ) ), 31 ) ); + mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10 + 16, lshift ) ), 31 ) ); flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); #ifdef DEBUG_ISSUE_1966 printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), - mult_32, mult_exp ); + mult_32, mult_exp ); #endif #endif } @@ -1519,9 +1519,9 @@ static void RefineThresholdsUsingPitch_fx( { #ifdef FIX_ISSUE_1966 if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) - printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), - (double) thresholdModification32[j] / (double) ( 1 << 26 ), - ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); + printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), + (double) thresholdModification32[j] / (double) ( 1 << 26 ), + ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); #else printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); #endif diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c old mode 100755 new mode 100644 index 5f538bf0a..3699f866f --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -11,7 +11,7 @@ #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -420,7 +420,7 @@ Word16 GetPLCModeDecision_fx( st->tonal_mdct_plc_active = 0; move16(); #ifdef DEBUG_ISSUE_1966 - //printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); + // printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); #endif } ELSE @@ -475,7 +475,7 @@ Word16 GetPLCModeDecision_fx( test(); test(); #ifdef DEBUG_ISSUE_1966 - //printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); + // printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); #endif IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index a734680fa..f6bccc0cb 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -40,7 +40,7 @@ #include "basop_proto_func.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c old mode 100755 new mode 100644 index 6174429ce..32ce1d1f4 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -13,7 +13,7 @@ #include "stat_com.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 +// #define DEBUG_ISSUE_1966 #ifdef DEBUG_ISSUE_1966 extern int32_t frame; @@ -642,7 +642,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); -#ifndef FIX_ISSUE_1966 +#ifndef FIX_ISSUE_1966 if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; @@ -849,7 +849,7 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( } #ifdef DEBUG_ISSUE_1966 - //printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + // printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, @@ -868,7 +868,7 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #ifdef DEBUG_ISSUE_1966 - //printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + // printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); @@ -1022,7 +1022,7 @@ void TonalMDCTConceal_Detect_fx( Word32 sns_int_scf_fx[FDNS_NPTS]; #ifdef DEBUG_ISSUE_1966 Word32 det_way = 0; - printf( "Calling TonalMDCTConceal_Detect in frame=%d\n", frame); + printf( "Calling TonalMDCTConceal_Detect in frame=%d\n", frame ); #endif set32_fx( sns_int_scf_fx, 0, FDNS_NPTS ); @@ -1163,7 +1163,7 @@ void TonalMDCTConceal_Detect_fx( powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } #ifdef DEBUG_ISSUE_1966 - //printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + // printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, @@ -1184,7 +1184,7 @@ void TonalMDCTConceal_Detect_fx( hTonalMDCTConc->nSamplesCore, extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ #ifdef DEBUG_ISSUE_1966 - //printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); + // printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); #endif } } -- GitLab From 5b65f28efd8603a36cf71e64d67ec7d48363f7d4 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 12:31:03 +0200 Subject: [PATCH 09/19] removed all provious DEBUG prints, extended tonal component detection with 32-bit F0 and thresholdModification[] for NON-EVS (EVS kept compatible), fixed phase range to -2PI..+2PI with 4 quadrants (see FIX_ISSUE_1966 in tonalMDCTconcealment_fx.c) --- lib_com/options.h | 2 + lib_dec/TonalComponentDetection_fx.c | 804 +++++++++------------------ lib_dec/er_util_fx.c | 25 - lib_dec/ivas_mdct_core_dec_fx.c | 37 -- lib_dec/tonalMDCTconcealment_fx.c | 102 +--- 5 files changed, 278 insertions(+), 692 deletions(-) mode change 100644 => 100755 lib_com/options.h mode change 100644 => 100755 lib_dec/ivas_mdct_core_dec_fx.c diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index 52de155d3..88a5dbcc8 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -140,6 +140,8 @@ #define FIX_FMSW_DEC /* float issue 1542: fix JBM issue in format switching */ #define FIX_FMSW_DEC_2 /* float issue 1575: fix crash for format switching when bitsream starts with EVS */ +#define FIX_ISSUE_1966 /* FhG: Basop issue 1966: shift phase range to [-2PI..+2PI[, handle 4 quadrants */ + /* FhG: Basop issue 1966: use 32-bit variables for F0 and thresholdModification */ /* ##################### End NON-BE switches ########################### */ /* ################## End MAINTENANCE switches ######################### */ diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 46b4cc042..25cb4300a 100755 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -12,131 +12,29 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" -//#define FIX_ISSUE_1966 -//#define DEBUG_ISSUE_1966 -#ifdef FIX_ISSUE_1966 -#include -#include -#endif - -#ifdef DEBUG_ISSUE_1966 -extern int32_t frame; -#endif - /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ +/* Note: + * This version of the module is a hybrid variant, that processes in 2 modes: + * EVS_MONO: works with 16-bit F0 and 16-bit thresholdModification[] + * other: works with 32-bit F0-32 and 32-bit thresholdModification32[] + */ + static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); -#ifdef FIX_ISSUE_1966 -static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 F0_32, Word32 *envelope, Word32 *smoothedSpectrum ); -#else static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); -#endif -static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, -#ifdef FIX_ISSUE_1966 - Word32 *const pOrigF0_32, -#endif - Word16 *const pF0 -#ifdef FIX_ISSUE_1966 - , - Word32 *const pF0_32 -#endif -); +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, + Word16 *const pOrigF0, Word32 *const pOrigF0_32, Word16 *const pF0, Word32 *const pF0_32, const Word16 element_mode ); static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); -#ifdef FIX_ISSUE_1966 -static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0, Word32 *pF0_32 ); -#else -static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); -#endif -#ifdef FIX_ISSUE_1966 -static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum ); -#else -static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); -#endif -static void modifyThreshold( Word16 i, Word16 F0, -#ifdef FIX_ISSUE_1966 - Word32 F0_32, -#endif - Word16 threshold, -#ifdef FIX_ISSUE_1966 - Word32 threshold_32, -#endif - Word16 *thresholdModification -#ifdef FIX_ISSUE_1966 - , - Word32 *thresholdModification_32 -#endif -); -static void modifyThresholds( Word16 F0, -#ifdef FIX_ISSUE_1966 - Word32 F0_32, -#endif - Word16 origF0, -#ifdef FIX_ISSUE_1966 - Word32 origF0_32, -#endif - Word16 *thresholdModification -#ifdef FIX_ISSUE_1966 - , - Word32 *thresholdModification_32 -#endif -); -#ifdef FIX_ISSUE_1966 -static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32 ); -#else -static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); -#endif - -#ifdef FIX_ISSUE_1966 -static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word32 F0_32, Word16 *thresholdModification, Word32 *thresholdModification32, Word16 element_mode ); -#else -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 ); -#endif - -#ifdef FIX_ISSUE_1966 -static inline int32_t double_to_q31_with_exp( double x, int *out_exp ) -{ - // Zerlege x in Mantisse und Exponent: x = m * 2^e, m in [0.5, 1) oder (-1, -0.5] - int e; - double m = frexp( x, &e ); // x = m * 2^e, mit |m| in (0.5, 1] - - // Normalisiere so, dass |m| in [0.5, 1). Wir möchten später m in [-1,1) skalieren. - // Wir wählen hier eine Darstellung mit Mantisse in [-1, 1). - // Skaliere Mantisse weiter nach [-1, 1) falls nötig: - // Keep m wie von frexp (|m| in (0.5,1]). Wir skalieren bei Bedarf: - // Wir wollen final m_q31 = round(m * 2^31) und e beibehalten, aber sicherstellen - // dass der resultierende Wert im Q31-Bereich liegt. - - // In Q31 kann Mantisse m_q31 = round(m * 2^31). - // Grenzen beachten: |m| < 1, also m_q31 liegt in (-2^31, 2^31-1). Wir saturieren ggf. - double scaled = m * (double) ( 1ULL << 31 ); // 2^31 - // Rundung - if ( scaled >= 0.0 ) - scaled += 0.5; - else - scaled -= 0.5; - - // Saturation in int32_t - if ( scaled > (double) INT32_MAX ) - scaled = (double) INT32_MAX; - if ( scaled < (double) INT32_MIN ) - scaled = (double) INT32_MIN; - - int32_t m_q31 = (int32_t) scaled; - - if ( out_exp ) - *out_exp = e; - - return m_q31; -} -// Optionaler Helper: Mantisse aus Q31 zurück zu double (nur zur Überprüfung) -static inline double q31_to_double( int32_t q31 ) -{ - // q31 → double in [-1, 1) - return ( (double) q31 ) / (double) ( 1ULL << 31 ); -} -#endif +static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0, Word32 *pF0_32, const Word16 element_mode ); +static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum, const Word16 element_mode ); +static void modifyThreshold( Word16 i, Word16 F0, Word32 F0_32, Word16 threshold, Word32 threshold_32, + Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); +static void modifyThresholds( Word16 F0, Word32 F0_32, Word16 origF0, Word32 origF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); +static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); +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, Word32 *thresholdModification32, const Word16 element_mode ); + /*-------------------------------------------------------------------* * DetectTonalComponents() @@ -169,18 +67,13 @@ void DetectTonalComponents_fx( ) { Word16 F0; -#ifdef FIX_ISSUE_1966 Word32 F0_32; Word32 thresholdModification32[L_FRAME_MAX]; -#endif Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; Word32 pScaledMdctSpectrum[L_FRAME_MAX]; Word16 nBands; Word32 sns_int_scf_fx[FDNS_NPTS]; /*Q16*/ Word16 q_pScaledMdctSpectrum; -#ifdef DEBUG_ISSUE_1966 - printf( "Calling DetectTonalComponents in frame=%d\n", frame ); -#endif set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); @@ -238,27 +131,19 @@ void DetectTonalComponents_fx( } /* Find peak candidates in the last frame. */ -#ifdef FIX_ISSUE_1966 - findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, thresholdModification32, floorPowerSpectrum ); -#else - findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); -#endif + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, thresholdModification32, floorPowerSpectrum, element_mode ); /* Refine peak candidates using the pitch information */ -#ifdef FIX_ISSUE_1966 RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, &F0_32, - thresholdModification, thresholdModification32 ); -#else - RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); -#endif + thresholdModification, thresholdModification32, element_mode ); /* Find peaks in the second last frame */ -#ifdef FIX_ISSUE_1966 + if (element_mode != EVS_MONO ) + { + F0 = extract_h( F0_32 ); + } findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, - F0, F0_32, thresholdModification, thresholdModification32, element_mode ); -#else - findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); -#endif + F0, thresholdModification, thresholdModification32, element_mode ); return; } @@ -425,9 +310,6 @@ static void getEnvelope( const Word16 nSamples, /*i : Q0 */ const Word32 *powerSpec, /*i : powerSpec_exp */ Word16 F0, /*i : 5Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 F0_32, /*i : 5Q10+Q16*/ -#endif Word32 *envelope, /*o : powerSpec_exp + LEVEL_EXP Q28*/ Word32 *smoothedSpectrum /*o : powerSpec_exp + LEVEL_EXP Q28*/ ) @@ -460,37 +342,6 @@ static void getEnvelope( nFilterLength = s_or( 1, shr( F0, 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ move16(); } -#ifdef DEBUG_ISSUE_1966 - printf("getEnvelope in frame=%d: F0=0x%04X nFilterLength=%d\n", frame, F0, nFilterLength); -#endif -#ifdef FIX_ISSUE_1966 - IF( F0_32 == 0 ) - { - nFilterLength = 15; /*Q0*/ - move16(); - } - ELSE IF( F0_32 <= (10240 << 16) /*10.0f Q10*/ ) - { - nFilterLength = 11; /*Q0*/ - move16(); - } - ELSE IF( F0_32 >= (22528 << 16) /*22.0f Q10*/ ) - { - /* For F0 >= 22 peak is isolated well enough with the filter length of 23. - This case is however not triggered due to the limit of pit_min, - but the line is left for security reasons. */ - nFilterLength = 23; /*Q0*/ - move16(); - } - ELSE - { - nFilterLength = s_or( 1, shr( extract_h(F0_32), 10 ) ); /*1+2*(int)(F0/2); F0->Q10*/ - move16(); - } -#ifdef DEBUG_ISSUE_1966 - printf( "getEnvelope in frame=%d: F0_32=0x%08X nFilterLength=%d\n", frame, F0_32, nFilterLength ); -#endif -#endif nHalfFilterLength = shr( nFilterLength, 1 ); @@ -558,14 +409,10 @@ static void GetF0( /*i - Qx */ /*is justed handed over and given back*/ Word32 /*int*/ const pitchLag, /*i - Q16*/ Word16 /*short*/ *const pOrigF0, /*o - Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 *const pOrigF0_32, -#endif - Word16 /*short*/ *const pF0 /*o - Q10*/ -#ifdef FIX_ISSUE_1966 - , - Word32 *const pF0_32 -#endif + Word32 *const pOrigF0_32, /*o - Q10+16*/ + Word16 /*short*/ *const pF0, /*o - Q10*/ + Word32 *const pF0_32, /*o - Q10+16*/ + const Word16 element_mode ) { Word16 /*short*/ tmpPitchLag; @@ -585,32 +432,25 @@ static void GetF0( = round_fx( L_shl( pitchLag, 4 ) ); /*no division by 2, will be done in following division - furthermore, do a leftshift before rounding, to preserve more accuracy - will be accommodated also in following division*/ - - /**pF0 = nSamplesCore/tmpPitchLag;*/ - BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ - *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ - move16(); - *pOrigF0 = *pF0; /*Q10*/ - move16(); - -#ifdef FIX_ISSUE_1966 - Word16 tmp_32 = 0; - Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton( L_shl( nSamplesCore, Q16 ), tmpPitchLag, &tmp_32 ); - F0_32 = L_shl( F0_32, tmp_32 - Q16 ); - *pF0_32 = F0_32; - move32(); - *pOrigF0_32 = *pF0_32; /*Q26*/ - move32(); -#endif -#ifdef DEBUG_ISSUE_1966 - static double err_max = 0.0; - double f0 = (double) *pF0 / ( 1 << 10 ); - double f0_32 = (double) *pF0_32 / ( 1 << 26 ); - double err = fabs( f0 - f0_32 ); - err_max = fmax( err_max, err ); - printf( "# GetF0 frame=%d *F0_32=0x%08x (%5.10f) *F0=0x%04x (%5.10f) err_max=%5.10f err=%5.10f, tmp_32=%d, tmp=%d \n", - frame, *pF0_32, f0_32, *pF0, f0, err_max, err, tmp_32, tmp ); -#endif + IF (element_mode == EVS_MONO) + { + /**pF0 = nSamplesCore/tmpPitchLag;*/ + BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ + *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ + move16(); + *pOrigF0 = *pF0; /*Q10*/ + move16(); + } + ELSE + { + Word16 tmp_32 = 0; + Word32 F0_32 = BASOP_Util_Divide3232_Scale_newton( L_shl( nSamplesCore, Q16 ), tmpPitchLag, &tmp_32 ); + F0_32 = L_shl( F0_32, tmp_32 - Q16 ); + *pF0_32 = F0_32; + move32(); + *pOrigF0_32 = *pF0_32; /*Q26*/ + move32(); + } tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) @@ -618,33 +458,40 @@ static void GetF0( move16(); tmp = nSamples; } -#ifdef FIX_ISSUE_1966 - BASOP_Util_Divide_MantExp( tmp, 15, extract_h( *pF0_32 ), 5, &nTotalHarmonics, &tmp ); - nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); - - /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ - findStrongestHarmonics( nSamples, powerSpectrum, extract_h( *pF0_32 ), nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); - CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0, pF0_32 ); -#else - BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); - nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); - /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ - findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); - CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0 ); -#endif + IF( element_mode == EVS_MONO ) + { + BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); + nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); + /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ + findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); + CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0, NULL, element_mode ); + } + ELSE + { + BASOP_Util_Divide_MantExp( tmp, 15, extract_h( *pF0_32 ), 5, &nTotalHarmonics, &tmp ); + nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); + + /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ + findStrongestHarmonics( nSamples, powerSpectrum, extract_h( *pF0_32 ), nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); + CorrectF0( rgiStrongHarmonics, nStrongHarmonics, NULL, pF0_32, element_mode ); + } } ELSE { - move16(); - move16(); - *pF0 = 0; - *pOrigF0 = 0; -#ifdef FIX_ISSUE_1966 - move32(); - move32(); - *pF0_32 = 0; - *pOrigF0_32 = 0; -#endif + IF( element_mode == EVS_MONO ) + { + move16(); + move16(); + *pF0 = 0; + *pOrigF0 = 0; + } + ELSE + { + move32(); + move32(); + *pF0_32 = 0; + *pOrigF0_32 = 0; + } } return; @@ -740,18 +587,14 @@ static void findStrongestHarmonics( static void CorrectF0( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ -#ifdef FIX_ISSUE_1966 Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ - Word32 /*long*/ *pF0_32 ) /*I/O - Q10+16 range: {0}, [4..18) */ -#else - Word16 /*short*/ *pF0 ) /*I/O - Q10 range: {0}, [4..18) */ -#endif + Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ + const Word16 element_mode ) { Word16 /*short*/ i; Word16 /*short*/ F0; -#ifdef FIX_ISSUE_1966 - Word32 F0_32; -#endif + Word32 /*long*/ F0_32; /* unused in EVS_MONO */ + Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ Word16 /*short*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; /*Q0*/ @@ -765,27 +608,32 @@ static void CorrectF0( move16(); } - F0 = *pF0; /*Q10*/ -#ifdef FIX_ISSUE_1966 - F0_32 = *pF0_32; -#endif - -#ifdef DEBUG_ISSUE_1966 - /* Condition should be identical for 16 or 32 version */ - if ( ( F0 == 0 ) && ( F0_32 != 0 ) ) - printf( "CorrectF0: F0 (0x%04X) != F0_32 (0x%08X)\n", F0, F0_32 ); -#endif + /* i = MAX_PEAKS_FROM_PITCH - 1 (9) now */ + IF (element_mode == EVS_MONO) + { + F0 = *pF0; /*Q10*/ + move16(); + test(); + if (F0 == 0 || nHarmonics == 0) + { + i = 0; /* skip processing */ + move16(); + } + } + ELSE + { + F0_32 = *pF0_32; + move32(); + test(); + if ( F0_32 == 0 || nHarmonics == 0 ) + { + i = 0; /* skip processing */ + move16(); + } + } - test(); -#ifdef FIX_ISSUE_1966 - IF( F0_32 > 0 && nHarmonics != 0 ) -#else - IF( F0 > 0 && nHarmonics != 0 ) -#endif + IF( i != 0 ) /* skip processing, if F0=0 or nHarmonics=0 */ { -#ifdef DEBUG_ISSUE_1966 - printf( "CorrectF0: - start - F0 (0x%04X), F0_32 (0x%08X)\n", F0, F0_32 ); -#endif tmp = sub( nHarmonics, 1 ); FOR( i = 0; i < tmp; i++ ) { @@ -888,25 +736,21 @@ static void CorrectF0( IF( LE_16( iMult, 3 ) ) { /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ - F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ -#ifdef FIX_ISSUE_1966 - F0_32 = L_shl_sat( Mpy_32_16_1( F0_32 /*Q10+16*/, iMostCommonDiff /*Q0*/ ), 15 ); /*Q10+16*/ -#endif -#ifdef DEBUG_ISSUE_1966 - printf( "CorrectF0: A F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); -#endif + IF( element_mode == EVS_MONO ) + { + F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ + } + ELSE + { + F0_32 = L_shl_sat( Mpy_32_16_1( F0_32 /*Q10+16*/, iMostCommonDiff /*Q0*/ ), 15 ); /*Q10+16*/ + } } ELSE { -#ifdef FIX_ISSUE_1966 - F0_32 = 0; - move32(); -#endif F0 = 0; move16(); -#ifdef DEBUG_ISSUE_1966 - printf( "CorrectF0: B F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); -#endif + F0_32 = 0; + move32(); } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ @@ -917,28 +761,23 @@ static void CorrectF0( if ( ( GT_16( iMostCommonDiff, 1 ) ) || ( LT_16( nMostCommonDiff, 3 ) ) ) { /* Not enough peaks at the same distance => don't use the pitch. */ -#ifdef FIX_ISSUE_1966 - F0_32 = 0; - move32(); -#endif F0 = 0; move16(); -#ifdef DEBUG_ISSUE_1966 - printf( "CorrectF0: C F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); -#endif + F0_32 = 0; + move32(); } } -#ifdef FIX_ISSUE_1966 - *pF0_32 = F0_32; - move32(); -#endif - *pF0 = F0; - move16(); + IF(element_mode == EVS_MONO) + { + *pF0 = F0; + move16(); + } + ELSE + { + *pF0_32 = F0_32; + move32(); + } } -#ifdef DEBUG_ISSUE_1966 - printf( "CorrectF0: D F0_32=0x%08X F0=0x%04X frame=%d\n", F0_32, F0, frame ); -#endif - return; } @@ -946,99 +785,73 @@ static void CorrectF0( static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ Word16 /*short*/ F0, /*I - Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 F0_32, /*I - Qi26*/ -#endif + Word32 F0_32, /*I - Q26*/ Word16 /*short*/ threshold, /*I - Q10*/ -#ifdef FIX_ISSUE_1966 Word32 threshold_32, /*I - Q26*/ -#endif - Word16 * /*short*/ thresholdModification /*I - Q10*/ -#ifdef FIX_ISSUE_1966 - , - Word32 * /*short*/ thresholdModification_32 -#endif + Word16 * /*short*/ thresholdModification, /*I - Q10*/ + Word32 * /*long*/ thresholdModification32, /*I - Q26*/ + const Word16 element_mode ) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; Word16 k /*Q0*/; Word16 twoTimesFract /*Q10*/; -#ifdef FIX_ISSUE_1966 - Word32 L_twoTimesFract /*Q10+16*/; -#endif - - harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ - k = extract_h( harmonic ); /*Q0*/ - fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ - twoTimesFract = mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ - move16(); - thresholdModification[k] = threshold; - move16(); - thresholdModification[k - 1] = add( threshold /*Q10*/, twoTimesFract /*Q10*/ ); /*Q10*/ - move16(); - thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ -#ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) -#if 0 - printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0 %15.15f fract %15.15f\n", k - 1, - (double) thresholdModification[k - 1] / ( 1 << 10 ), - (double) thresholdModification[k + 0] / ( 1 << 10 ), - (double) thresholdModification[k + 1] / ( 1 << 10 ), - (double) F0 / ( 1 << 10 ), - (double) twoTimesFract / (1 << 10) ); -#endif -#endif - -#ifdef FIX_ISSUE_1966 - harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) ); /*Q0 * Q10 = 15Q16*/ - k = extract_h( harmonic ); /*Q0*/ - fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ - L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + IF( EQ_16( element_mode, EVS_MONO ) ) + { + harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ + k = extract_h( harmonic ); /*Q0*/ + fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ + twoTimesFract = mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ - move32(); - thresholdModification_32[k] = threshold_32;/*Q10+16*/ - move32(); - thresholdModification_32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/ - move32(); - thresholdModification_32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ -#ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) - if (( thresholdModification_32[k + 0] != (16 << 26) ) && ( thresholdModification[k + 0] != (16 << 10) ) ) - printf( "modifyThreshold[%d] %15.15f %15.15f %15.15f F0_32 %15.15f fract %15.15f diff=%15.15f\n", k - 1, - (double) thresholdModification_32[k - 1] / ( 1 << 26 ), - (double) thresholdModification_32[k + 0] / ( 1 << 26 ), - (double) thresholdModification_32[k + 1] / ( 1 << 26 ), - (double) F0_32 / ( 1 << 26 ), - (double) L_twoTimesFract / ( 1 << 26 ), - (double) thresholdModification_32[k + 0] / ( 1 << 26 ) - (double) thresholdModification[k + 0] / ( 1 << 10 ) ); -#endif -#endif + move16(); + thresholdModification[k] = threshold; + move16(); + thresholdModification[k - 1] = add( threshold /*Q10*/, twoTimesFract /*Q10*/ ); /*Q10*/ + move16(); + thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ + } + ELSE + { + Word32 L_twoTimesFract /*Q10+16*/; + harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) ); /*Q0 * Q10 = 15Q16*/ + k = extract_h( harmonic ); /*Q0*/ + fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ + L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + move32(); + thresholdModification32[k] = threshold_32;/*Q10+16*/ + move32(); + thresholdModification32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/ + move32(); + thresholdModification32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ + } return; } static void modifyThresholds( Word16 /*short*/ F0, /*I - Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 F0_32, /*I - Qi26*/ -#endif + Word32 F0_32, /*I - Q26*/ Word16 /*short*/ origF0, /*I - Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 origF0_32, /*I - Qi26*/ -#endif - Word16 * /*short*/ thresholdModification -#ifdef FIX_ISSUE_1966 - , - Word32 * /*short*/ thresholdModification_32 -#endif + Word32 origF0_32, /*I - Q26*/ + Word16 * /*short*/ thresholdModification, /*Q10*/ + Word32 * /*short*/ thresholdModification32, /*Q26*/ + const Word16 element_mode ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; + /* Note: in case besides EVS_MONO, we set the 16-bit variables */ + /* accordingly and control further processing with those. */ + IF(element_mode != EVS_MONO) + { + origF0 = extract_h(origF0_32); + F0 = extract_h(F0_32); + } + IF( origF0 > 0 ) { IF( F0 == 0 ) @@ -1047,20 +860,10 @@ static void modifyThresholds( FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold( i, origF0, -#ifdef FIX_ISSUE_1966 - origF0_32, -#endif - 717 /*0.7f in Q10*/, -#ifdef FIX_ISSUE_1966 - 46976205 /*0.7f in Q10+16*/, -#endif - thresholdModification -#ifdef FIX_ISSUE_1966 - , - thresholdModification_32 -#endif - ); + modifyThreshold( i, origF0, origF0_32, + 717 /*0.7f in Q10*/, 46976205 /*0.7f in Q10+16*/, + thresholdModification, thresholdModification32, + element_mode ); } } IF( F0 > 0 ) @@ -1073,37 +876,17 @@ static void modifyThresholds( FOR( i = tmp; i > 0; i-- ) { - modifyThreshold( i, origF0, -#ifdef FIX_ISSUE_1966 - origF0_32, -#endif - 358 /*0.35f in Q10*/, -#ifdef FIX_ISSUE_1966 - 23488102 /*0.35 in Q10+16*/, -#endif - thresholdModification -#ifdef FIX_ISSUE_1966 - , - thresholdModification_32 -#endif - ); + modifyThreshold( i, origF0, origF0_32, + 358 /*0.35f in Q10*/, 23488102 /*0.35 in Q10+16*/, + thresholdModification, thresholdModification32, + element_mode ); } FOR( i = 1; i <= nHarmonics; i++ ) { - modifyThreshold( i, F0, -#ifdef FIX_ISSUE_1966 - F0_32, -#endif - 358 /*0.35f Q10*/, -#ifdef FIX_ISSUE_1966 - 23488102 /*0.35 in Q10+16*/, -#endif - thresholdModification -#ifdef FIX_ISSUE_1966 - , - thresholdModification_32 -#endif - ); + modifyThreshold( i, F0, F0_32, + 358 /*0.35f Q10*/, 23488102 /*0.35 in Q10+16*/, + thresholdModification, thresholdModification32, + element_mode ); } } } @@ -1117,10 +900,10 @@ static void findCandidates( const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ -#ifdef FIX_ISSUE_1966 + /* Note: the next array is only available if not in EVS_MONO mode */ Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ -#endif - Word16 floorPowerSpectrum /* i : lower limit for power spectrum bins Q0*/ + Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ + const Word16 element_mode /* i : EVS_MONO or anything else */ ) { Word32 powerSpectrum[L_FRAME_MAX]; @@ -1133,18 +916,15 @@ static void findCandidates( Word16 tmp_loop1, tmp_loop2, tmp_loop3; calcPseudoSpec( MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp ); - -#ifdef FIX_ISSUE_1966 - getEnvelope( nSamples, powerSpectrum, 0, (Word32) 0, envelope, smoothedSpectrum ); -#else getEnvelope( nSamples, powerSpectrum, 0, envelope, smoothedSpectrum ); -#endif - - set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ -#ifdef FIX_ISSUE_1966 - set32_fx( thresholdModificationNew32, ( UNREACHABLE_THRESHOLD ) << 16, nSamples ); /*Q10+Q16*/ - -#endif + IF (EQ_16( element_mode , EVS_MONO ) ) + { + set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ + } + ELSE + { + set32_fx( thresholdModificationNew32, ( UNREACHABLE_THRESHOLD ) << 16, nSamples ); /*Q10+Q16*/ + } k = GROUP_LENGTH / 2; move16(); @@ -1234,23 +1014,32 @@ static void findCandidates( /* Modify thresholds for the following frame */ tmp_loop3 = add( k, 2 ); - FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) + IF( EQ_16( element_mode, EVS_MONO ) ) { - thresholdModificationNew[j] = BIG_THRESHOLD; /*Q10*/ - move16(); -#ifdef FIX_ISSUE_1966 - thresholdModificationNew32[j] = BIG_THRESHOLD << 16; /* 1.5f in Q10+Q16*/ - move32(); -#endif - - if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) + FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) { - thresholdModificationNew[j] = SMALL_THRESHOLD; /*Q10*/ + thresholdModificationNew[j] = BIG_THRESHOLD; /*Q10*/ move16(); -#ifdef FIX_ISSUE_1966 - thresholdModificationNew32[j] = 73819750; /* 1.1f in Q10+Q16*/ + + if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) + { + thresholdModificationNew[j] = SMALL_THRESHOLD; /*Q10*/ + move16(); + } + } + } + ELSE + { + FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) + { + thresholdModificationNew32[j] = BIG_THRESHOLD << 16; /* 1.5f in Q10+Q16*/ move32(); -#endif + + if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) + { + thresholdModificationNew32[j] = 73819750; /* 1.1f in Q10+Q16*/ + move32(); + } } } /* Jump to the next foot of the peak. */ @@ -1274,14 +1063,9 @@ static void findTonalComponents_fx( const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, Word16 F0, /* IN */ -#ifdef FIX_ISSUE_1966 - Word32 F0_32, /* IN */ -#endif Word16 *thresholdModification, /* IN Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 *thresholdModification32, /* IN Q10+Q16*/ -#endif - Word16 element_mode ) /* IN */ + Word32 *thresholdModification32, /* IN Q10+Q16, unused in EVS_MONO */ + const Word16 element_mode ) /* IN, EVS_MONO or anything else */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -1291,29 +1075,7 @@ static void findTonalComponents_fx( Word32 biggerNeighbor; Word16 tmp_loop1, tmp_loop2, tmp_loop3; -#ifdef DEBUG_ISSUE_1966 - //if ( frame == 1384 ) - //{ -printf( "findTonalComponents in frame %d\n", frame); - for ( j = 0; j < nSamples; j++ ) - { -#ifdef FIX_ISSUE_1966 - if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) - printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), - (double) thresholdModification32[j] / (double) ( 1 << 26 ), - ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); -#else - printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); -#endif - } - //} -#endif - -#ifdef FIX_ISSUE_1966 - getEnvelope( nSamples, powerSpectrum, F0, F0_32, envelope, smoothedSpectrum ); -#else getEnvelope( nSamples, powerSpectrum, F0, envelope, smoothedSpectrum ); -#endif nrOfFIS = 0; move16(); @@ -1334,26 +1096,25 @@ printf( "findTonalComponents in frame %d\n", frame); } ELSE { - 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 ) ); - flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); -#ifdef DEBUG_ISSUE_1966 - printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), - mult_32, mult_exp ); -#endif -#ifdef FIX_ISSUE_1966 - mult_64 = W_mult_32_32( envelope[k], thresholdModification32[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10+16 - lshift = W_norm( mult_64 ); - mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 - mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10+16, lshift ) ), 31 ) ); + Word64 mult_64; + Word16 lshift; + Word16 mult_exp; + Word32 mult_32; + IF( element_mode == EVS_MONO ) + { + mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 + lshift = W_norm( mult_64 ); + mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 + mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); + } + ELSE + { + mult_64 = W_mult_32_32( envelope[k], thresholdModification32[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10+16 + lshift = W_norm( mult_64 ); + mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 + mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10 + 16, lshift ) ), 31 ) ); + } flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); -#ifdef DEBUG_ISSUE_1966 - printf( " k=%d ->flag: %d spec: 0x%08X (%d) mult: 0x%08X (%d)\n", k, flag, smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), - mult_32, mult_exp ); -#endif -#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 */ @@ -1463,10 +1224,6 @@ printf( "findTonalComponents in frame %d\n", frame); indexOfTonalPeak[nrOfFIS++] = k; move16(); -#ifdef DEBUG_ISSUE_1966 - if ( frame == 1384 ) - printf( "nrOfFIS=%d k=%d\n", nrOfFIS, k ); -#endif IF( EQ_16( nrOfFIS, MAX_NUMBER_OF_IDX ) ) { @@ -1489,46 +1246,21 @@ printf( "findTonalComponents in frame %d\n", frame); static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, - const Word32 powerSpectrum[], /*Qx*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - Word16 *pF0, /*Q10*/ -#ifdef FIX_ISSUE_1966 - Word32 *pF0_32, /*Q10+Q16*/ -#endif - Word16 *thresholdModification /*Q10*/ -#ifdef FIX_ISSUE_1966 - , - Word32 *thresholdModification32 /*Q10+Q16*/ -#endif + const Word32 powerSpectrum[], /*Qx*/ + const Word32 lastPitchLag, /*Qx*/ + const Word32 currentPitchLag, /*Qx*/ + Word16 *pF0, /*Q10*/ + Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ + Word16 *thresholdModification, /*Q10*/ + Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ + const Word16 element_mode ) { Word16 pitchIsStable; Word16 origF0; -#ifdef FIX_ISSUE_1966 - Word32 origF0_32; -#endif + Word32 origF0_32; /* unused in EVS_MONO mode */ Word32 L_tmp; - -#ifdef DEBUG_ISSUE_1966 - // if ( frame == 1384 ) - //{ - printf( "RefineThresholdsUsingPitch in frame %d\n", frame ); - for ( int j = 0; j < nSamples; j++ ) - { -#ifdef FIX_ISSUE_1966 - if ( ( thresholdModification32[j] != ( 16 << 26 ) ) && ( thresholdModification[j] != ( 16 << 10 ) ) ) - printf( "thresholdModification[%3d]=%15.15f (16) %15.15f (32) diff=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ), - (double) thresholdModification32[j] / (double) ( 1 << 26 ), - ( (double) thresholdModification[j] / (double) ( 1 << 10 ) ) - ( (double) thresholdModification32[j] / (double) ( 1 << 26 ) ) ); -#else - printf( "thresholdModification[%3d]=%15.15f\n", j, (double) thresholdModification[j] / (double) ( 1 << 10 ) ); -#endif - } - //} -#endif - /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ pitchIsStable = 0; move16(); @@ -1541,40 +1273,24 @@ static void RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { - GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, -#ifdef FIX_ISSUE_1966 - &origF0_32, -#endif - pF0 -#ifdef FIX_ISSUE_1966 - , - pF0_32 -#endif - ); - - modifyThresholds( *pF0, -#ifdef FIX_ISSUE_1966 - *pF0_32, -#endif - origF0, -#ifdef FIX_ISSUE_1966 - origF0_32, -#endif - thresholdModification -#ifdef FIX_ISSUE_1966 - , - thresholdModification32 -#endif - ); + GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, + &origF0, &origF0_32, pF0, pF0_32, element_mode ); + + modifyThresholds( *pF0, *pF0_32, origF0, origF0_32, + thresholdModification, thresholdModification32, element_mode ); } ELSE { - *pF0 = 0; - move16(); -#ifdef FIX_ISSUE_1966 - *pF0_32 = 0; - move32(); -#endif + IF( EQ_16( element_mode, EVS_MONO ) ) + { + *pF0 = 0; + move16(); + } + ELSE + { + *pF0_32 = 0; + move32(); + } } return; diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 5f538bf0a..888a0cd1c 100755 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -10,13 +10,6 @@ #include #include "ivas_prot_fx.h" - -//#define DEBUG_ISSUE_1966 - -#ifdef DEBUG_ISSUE_1966 -extern int32_t frame; -#endif - /* static void setnoiseLevelMemory_fx() * * Helper function - updates buffer for minimumStatistics_fx function @@ -381,9 +374,6 @@ Word16 GetPLCModeDecision_fx( TCX_DEC_HANDLE hTcxDec; hTcxDec = st->hTcxDec; -#ifdef DEBUG_ISSUE_1966 - printf( "Calling GetPLCModeDecision in frame=%d\n", frame ); -#endif IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { @@ -419,9 +409,6 @@ Word16 GetPLCModeDecision_fx( } st->tonal_mdct_plc_active = 0; move16(); -#ifdef DEBUG_ISSUE_1966 - //printf( "-->tonal_mdct_plc_active=%d F1\n", st->tonal_mdct_plc_active ); -#endif } ELSE { @@ -439,9 +426,6 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); -#ifdef DEBUG_ISSUE_1966 - printf( "-->tonal_mdct_plc_active=%d F2\n", st->tonal_mdct_plc_active ); -#endif IF( !( st->rf_flag && st->use_partial_copy && ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) || EQ_16( st->rf_frame_type, RF_TCXTD2 ) ) ) ) { test(); @@ -474,18 +458,12 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); -#ifdef DEBUG_ISSUE_1966 - //printf( "-->pitch=%f numIndices=%2d\n", (double) pitch / (double) ( 1 << 16 ), numIndices ); -#endif IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( ( numIndices > 0 ) && ( ( LE_16( st->last_good, UNVOICED_TRANSITION ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) ) { core = TCX_20_CORE; move16(); st->tonal_mdct_plc_active = 1; move16(); -#ifdef DEBUG_ISSUE_1966 - printf( "-->tonal_mdct_plc_active=%d F21\n", st->tonal_mdct_plc_active ); -#endif } ELSE IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { @@ -505,9 +483,6 @@ Word16 GetPLCModeDecision_fx( } } } -#ifdef DEBUG_ISSUE_1966 - printf( "X->tonal_mdct_plc_active=%d F3\n", st->tonal_mdct_plc_active ); -#endif return core; /*Q0*/ } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c old mode 100644 new mode 100755 index a734680fa..397a0728e --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -40,11 +40,6 @@ #include "basop_proto_func.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 - -#ifdef DEBUG_ISSUE_1966 -extern int32_t frame; -#endif /*-----------------------------------------------------------------* * Function mdct_read_IGF_bits() * @@ -1520,10 +1515,6 @@ void ivas_mdct_core_tns_ns_fx( Word16 exp, length; #endif -#ifdef DEBUG_ISSUE_1966 - printf( "Calling ivas_mdct_core_tns_ns in frame=%d\n", frame ); -#endif - /* Initializations */ sts = hCPE->hCoreCoder; bfi = sts[0]->bfi; @@ -1537,9 +1528,6 @@ void ivas_mdct_core_tns_ns_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F1\n", ch, st->tonal_mdct_plc_active ); -#endif #ifdef FIX_BASOP_2555_FRAMELEN_CALC IF( EQ_16( st->core, TCX_20_CORE ) ) { @@ -1601,9 +1589,6 @@ void ivas_mdct_core_tns_ns_fx( IF( st->hTonalMDCTConc != NULL ) { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, 0, bfi, 0 ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F2\n", ch, st->tonal_mdct_plc_active ); -#endif } /* nothing to do for missing LFE */ @@ -1615,10 +1600,6 @@ void ivas_mdct_core_tns_ns_fx( init_tcx_info_fx( st, L_frame_global[ch], L_frameTCX_glob[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F3 k=%d\n", ch, st->tonal_mdct_plc_active, k ); -#endif - Word16 q_x; q_x = sub( 31, x_e ); IF( bfi == 0 ) @@ -1640,9 +1621,6 @@ void ivas_mdct_core_tns_ns_fx( move16(); } TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline_fx( st, L_frame[ch], L_frameTCX[ch] ) ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F4 k=%d\n", ch, st->tonal_mdct_plc_active, k ); -#endif } } ELSE @@ -1701,9 +1679,6 @@ void ivas_mdct_core_tns_ns_fx( } Scale_sig32( &x_fx[ch][k][0], length, -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x_fx[ch][k], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 1, &length ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F5 k=%d\n", ch, st->tonal_mdct_plc_active, k ); -#endif norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); @@ -1762,9 +1737,6 @@ void ivas_mdct_core_tns_ns_fx( } Scale_sig32( &x_fx[ch][k][0], length, -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0, &length ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F6 k=%d\n", ch, st->tonal_mdct_plc_active, k ); -#endif Scale_sig32( &x_fx[ch][k][0], length, sub( sub( 31, q_x ), x_e ) ); } @@ -1777,9 +1749,6 @@ void ivas_mdct_core_tns_ns_fx( } TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], x_e, st->hTcxCfg->psychParamsCurrent ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d F7\n", ch, st->tonal_mdct_plc_active ); -#endif } test(); @@ -1789,16 +1758,10 @@ void ivas_mdct_core_tns_ns_fx( IF( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], st->old_fpitch, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d bfi=%d F8-A\n", ch, st->tonal_mdct_plc_active, bfi ); -#endif } ELSE { TonalMDCTConceal_UpdateState_fx( st->hTonalMDCTConc, L_frameTCX[ch], 0, bfi, (Word8) s_and( bfi, st->tonal_mdct_plc_active ) ); -#ifdef DEBUG_ISSUE_1966 - printf( "->ch=%d tonal_mdct_plc_active=%d bfi=%d F8-B\n", ch, st->tonal_mdct_plc_active, bfi ); -#endif } } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 6174429ce..a33584b47 100755 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -13,12 +13,6 @@ #include "stat_com.h" #include "ivas_prot_fx.h" -//#define DEBUG_ISSUE_1966 - -#ifdef DEBUG_ISSUE_1966 -extern int32_t frame; -#endif - #define CROSSFADE_THRESHOLD ( 32762 ) // close to 1.0f in Q15 such that (x == 1.0f) is true /************************************************************************************ @@ -523,10 +517,6 @@ void TonalMDCTConceal_UpdateState_fx( const Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; -#ifdef DEBUG_ISSUE_1966 - printf( "Calling TonalMDCTConceal_UpdateState in frame=%d: ns=%d pl=%f bB=%d tCA=%d\n", - frame, nNewSamples, (double) pitchLag / (double) ( 1 << 16 ), badBlock, tonalConcealmentActive ); -#endif assert( !( !badBlock && tonalConcealmentActive ) ); @@ -616,11 +606,6 @@ static void FindPhaseDifferences( Word16 divi, s, j; Word32 a, Q, L_tmp, m, n; -#ifdef DEBUG_ISSUE_1966 - int a_way; - printf( "Calling FindPhaseDifferences: numIndexes=%d frame=%d\n", hTonalMDCTConc->pTCI->numIndexes, frame ); -#endif - s = SS; move16(); j = J; @@ -642,13 +627,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); -#ifndef FIX_ISSUE_1966 - if ( s_and( k, 1 ) != 0 ) - { - phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; - move16(); - } -#else +#ifdef FIX_ISSUE_1966 if ( EQ_16( s_and( k, 3 ), 1 ) ) { phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; @@ -664,10 +643,13 @@ static void FindPhaseDifferences( phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; move16(); } -#endif -#ifdef DEBUG_ISSUE_1966 - fractional = 0; // only for debug - a_way = 1; + +#else + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; + move16(); + } #endif } ELSE @@ -676,13 +658,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); -#ifndef FIX_ISSUE_1966 - if ( s_and( k, 1 ) != 0 ) - { - phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ - move16(); - } -#else +#ifdef FIX_ISSUE_1966 if ( EQ_16( s_and( k, 3 ), 1 ) ) { phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; @@ -698,10 +674,12 @@ static void FindPhaseDifferences( phaseDiff[i] = 0 /* 0*EVS_PI 3Q12*/; move16(); } -#endif -#ifdef DEBUG_ISSUE_1966 - fractional = 0; // only for debug - a_way = 2; +#else + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ + move16(); + } #endif } ELSE @@ -762,20 +740,8 @@ static void FindPhaseDifferences( } phaseDiff[i] = round_fx( L_shl( L_tmp, 1 ) ); /*3Q12*/ move16(); -#ifdef DEBUG_ISSUE_1966 - a_way = 3; -#endif } } -#ifdef DEBUG_ISSUE_1966 - printf( "phaseDiff[%3d]=%15.15f frac=%15.15f a_way=%d\n l/r=%15.15f k=%d\n", - i, - (double) phaseDiff[i] / (double) ( 1 << 12 ), - ( a_way == 3 ) ? (double) L_mult( fractional, 28672 ) / (double) ( 1 << 27 ) : 0.f, - a_way, - (double) powerSpectrum[k - 1] / (double) powerSpectrum[k + 1], - hTonalMDCTConc->pTCI->indexOfTonalPeak[i] ); -#endif } return; @@ -848,9 +814,6 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( spectralData_exp = add( hTonalMDCTConc->lastBlockData.spectralData_exp, hTonalMDCTConc->lastBlockData.gain_tcx_exp ); } -#ifdef DEBUG_ISSUE_1966 - //printf( "Before DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); -#endif DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -867,9 +830,6 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( nSamples, hTonalMDCTConc->nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); -#ifdef DEBUG_ISSUE_1966 - //printf( "Behind DetectTonalComponents_fx: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); -#endif FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); @@ -1020,10 +980,7 @@ void TonalMDCTConceal_Detect_fx( Word16 i, powerSpectrum_exp, secondLastMDST_exp, s; Word16 nSamples; Word32 sns_int_scf_fx[FDNS_NPTS]; -#ifdef DEBUG_ISSUE_1966 - Word32 det_way = 0; - printf( "Calling TonalMDCTConceal_Detect in frame=%d\n", frame); -#endif + set32_fx( sns_int_scf_fx, 0, FDNS_NPTS ); nSamples = hTonalMDCTConc->nSamples; @@ -1054,10 +1011,6 @@ void TonalMDCTConceal_Detect_fx( { IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { -#ifdef DEBUG_ISSUE_1966 - det_way = 1; -#endif - CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; @@ -1106,9 +1059,6 @@ void TonalMDCTConceal_Detect_fx( } ELSE { -#ifdef DEBUG_ISSUE_1966 - det_way = 2; -#endif /* If the second last frame was also lost, it is expected that pastTimeSignal could hold a bit different signal (e.g. including fade-out) from the one stored in TonalMDCTConceal_SaveTimeSignal. */ /* That is why we reuse the already stored information about the concealed spectrum in the second last frame */ Word16 temp_power_spectrum_q = 0; @@ -1121,9 +1071,6 @@ void TonalMDCTConceal_Detect_fx( } IF( psychParamsCurrent == NULL ) { -#ifdef DEBUG_ISSUE_1966 - det_way = 21; -#endif mdct_shaping_16( hTonalMDCTConc->secondLastPowerSpectrum, hTonalMDCTConc->nSamplesCore, nSamples, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp, hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, powerSpectrum ); @@ -1143,9 +1090,6 @@ void TonalMDCTConceal_Detect_fx( } ELSE { -#ifdef DEBUG_ISSUE_1966 - det_way = 22; -#endif FOR( i = 0; i < FDNS_NPTS; i++ ) { sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], add( 1, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q16 @@ -1162,9 +1106,6 @@ void TonalMDCTConceal_Detect_fx( } powerSpectrum_exp = sub( 31, sub( shl( sub( Q31 - 3, powerSpectrum_exp ), 1 ), 31 ) ); } -#ifdef DEBUG_ISSUE_1966 - //printf( "Before RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); -#endif RefineTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -1183,26 +1124,15 @@ void TonalMDCTConceal_Detect_fx( nSamples, hTonalMDCTConc->nSamplesCore, extract_l( Mpy_32_16_1( L_mult0( hTonalMDCTConc->nSamples, hTonalMDCTConc->nSamples ), 82 ) ), element_mode, psychParamsCurrent ); /* floorPowerSpectrum */ -#ifdef DEBUG_ISSUE_1966 - //printf( "After RefineTonalComponents: hTonalMDCTConc->pTCI->numIndexes=%d\n", hTonalMDCTConc->pTCI->numIndexes ); -#endif } } } ELSE { -#ifdef DEBUG_ISSUE_1966 - det_way = 3; -#endif - hTonalMDCTConc->pTCI->numIndexes = 0; move16(); } -#ifdef DEBUG_ISSUE_1966 - printf( "Using TonalMDCTConceal_Detect in path=%d\n", det_way ); -#endif - *numIndices = hTonalMDCTConc->pTCI->numIndexes; move16(); -- GitLab From 2c13ff050d7d0fcd8d5db8ece6226fb99222dbbb Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 14:28:55 +0200 Subject: [PATCH 10/19] fix clang format --- lib_dec/TonalComponentDetection_fx.c | 92 +++++++++++++--------------- 1 file changed, 43 insertions(+), 49 deletions(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index 25cb4300a..fa9c9db7a --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -24,13 +24,11 @@ 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, Word32 *const pOrigF0_32, Word16 *const pF0, Word32 *const pF0_32, const Word16 element_mode ); +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word32 *const pOrigF0_32, Word16 *const pF0, Word32 *const pF0_32, const Word16 element_mode ); 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, Word32 *pF0_32, const Word16 element_mode ); static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum, const Word16 element_mode ); -static void modifyThreshold( Word16 i, Word16 F0, Word32 F0_32, Word16 threshold, Word32 threshold_32, - Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); +static void modifyThreshold( Word16 i, Word16 F0, Word32 F0_32, Word16 threshold, Word32 threshold_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); static void modifyThresholds( Word16 F0, Word32 F0_32, Word16 origF0, Word32 origF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); 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, Word32 *thresholdModification32, const Word16 element_mode ); @@ -138,12 +136,12 @@ void DetectTonalComponents_fx( thresholdModification, thresholdModification32, element_mode ); /* Find peaks in the second last frame */ - if (element_mode != EVS_MONO ) + if ( element_mode != EVS_MONO ) { F0 = extract_h( F0_32 ); } findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, - F0, thresholdModification, thresholdModification32, element_mode ); + F0, thresholdModification, thresholdModification32, element_mode ); return; } @@ -412,8 +410,7 @@ static void GetF0( Word32 *const pOrigF0_32, /*o - Q10+16*/ Word16 /*short*/ *const pF0, /*o - Q10*/ Word32 *const pF0_32, /*o - Q10+16*/ - const Word16 element_mode -) + const Word16 element_mode ) { Word16 /*short*/ tmpPitchLag; Word16 /*short*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; /*Q0*/ @@ -432,7 +429,7 @@ static void GetF0( = round_fx( L_shl( pitchLag, 4 ) ); /*no division by 2, will be done in following division - furthermore, do a leftshift before rounding, to preserve more accuracy - will be accommodated also in following division*/ - IF (element_mode == EVS_MONO) + IF( element_mode == EVS_MONO ) { /**pF0 = nSamplesCore/tmpPitchLag;*/ BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ @@ -587,8 +584,8 @@ static void findStrongestHarmonics( static void CorrectF0( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ - Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ - Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ + Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ + Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ const Word16 element_mode ) { Word16 /*short*/ i; @@ -609,12 +606,12 @@ static void CorrectF0( } /* i = MAX_PEAKS_FROM_PITCH - 1 (9) now */ - IF (element_mode == EVS_MONO) + IF( element_mode == EVS_MONO ) { F0 = *pF0; /*Q10*/ move16(); test(); - if (F0 == 0 || nHarmonics == 0) + if ( F0 == 0 || nHarmonics == 0 ) { i = 0; /* skip processing */ move16(); @@ -632,7 +629,7 @@ static void CorrectF0( } } - IF( i != 0 ) /* skip processing, if F0=0 or nHarmonics=0 */ + IF( i != 0 ) /* skip processing, if F0=0 or nHarmonics=0 */ { tmp = sub( nHarmonics, 1 ); FOR( i = 0; i < tmp; i++ ) @@ -767,7 +764,7 @@ static void CorrectF0( move32(); } } - IF(element_mode == EVS_MONO) + IF( element_mode == EVS_MONO ) { *pF0 = F0; move16(); @@ -783,15 +780,14 @@ static void CorrectF0( static void modifyThreshold( - Word16 /*short*/ i, /*I - Q0 */ - Word16 /*short*/ F0, /*I - Q10*/ - Word32 F0_32, /*I - Q26*/ - Word16 /*short*/ threshold, /*I - Q10*/ - Word32 threshold_32, /*I - Q26*/ - Word16 * /*short*/ thresholdModification, /*I - Q10*/ + Word16 /*short*/ i, /*I - Q0 */ + Word16 /*short*/ F0, /*I - Q10*/ + Word32 F0_32, /*I - Q26*/ + Word16 /*short*/ threshold, /*I - Q10*/ + Word32 threshold_32, /*I - Q26*/ + Word16 * /*short*/ thresholdModification, /*I - Q10*/ Word32 * /*long*/ thresholdModification32, /*I - Q26*/ - const Word16 element_mode - ) /*I/O - Q10*/ + const Word16 element_mode ) /*I/O - Q10*/ { Word32 harmonic; Word16 fractional /*Q15*/; @@ -818,10 +814,10 @@ static void modifyThreshold( harmonic = Mpy_32_16_1( F0_32, shl( i, 5 ) ); /*Q0 * Q10 = 15Q16*/ k = extract_h( harmonic ); /*Q0*/ fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ - L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + L_twoTimesFract = L_mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10+16*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ move32(); - thresholdModification32[k] = threshold_32;/*Q10+16*/ + thresholdModification32[k] = threshold_32; /*Q10+16*/ move32(); thresholdModification32[k - 1] = L_add( threshold_32 /*Q10+16*/, L_twoTimesFract /*Q10+16*/ ); /*Q10+16*/ move32(); @@ -832,24 +828,23 @@ static void modifyThreshold( static void modifyThresholds( - Word16 /*short*/ F0, /*I - Q10*/ - Word32 F0_32, /*I - Q26*/ - Word16 /*short*/ origF0, /*I - Q10*/ - Word32 origF0_32, /*I - Q26*/ - Word16 * /*short*/ thresholdModification, /*Q10*/ + Word16 /*short*/ F0, /*I - Q10*/ + Word32 F0_32, /*I - Q26*/ + Word16 /*short*/ origF0, /*I - Q10*/ + Word32 origF0_32, /*I - Q26*/ + Word16 * /*short*/ thresholdModification, /*Q10*/ Word32 * /*short*/ thresholdModification32, /*Q26*/ - const Word16 element_mode - ) /*I/O - Q10*/ + const Word16 element_mode ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; /* Note: in case besides EVS_MONO, we set the 16-bit variables */ /* accordingly and control further processing with those. */ - IF(element_mode != EVS_MONO) + IF( element_mode != EVS_MONO ) { - origF0 = extract_h(origF0_32); - F0 = extract_h(F0_32); + origF0 = extract_h( origF0_32 ); + F0 = extract_h( F0_32 ); } IF( origF0 > 0 ) @@ -902,8 +897,8 @@ static void findCandidates( Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ /* Note: the next array is only available if not in EVS_MONO mode */ Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ - Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ - const Word16 element_mode /* i : EVS_MONO or anything else */ + Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ + const Word16 element_mode /* i : EVS_MONO or anything else */ ) { Word32 powerSpectrum[L_FRAME_MAX]; @@ -917,7 +912,7 @@ static void findCandidates( calcPseudoSpec( MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp ); getEnvelope( nSamples, powerSpectrum, 0, envelope, smoothedSpectrum ); - IF (EQ_16( element_mode , EVS_MONO ) ) + IF( EQ_16( element_mode, EVS_MONO ) ) { set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ } @@ -1062,10 +1057,10 @@ static void findTonalComponents_fx( Word16 nSamples, /* IN */ const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, - Word16 F0, /* IN */ - Word16 *thresholdModification, /* IN Q10*/ + Word16 F0, /* IN */ + Word16 *thresholdModification, /* IN Q10*/ Word32 *thresholdModification32, /* IN Q10+Q16, unused in EVS_MONO */ - const Word16 element_mode ) /* IN, EVS_MONO or anything else */ + const Word16 element_mode ) /* IN, EVS_MONO or anything else */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -1246,15 +1241,14 @@ static void findTonalComponents_fx( static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, - const Word32 powerSpectrum[], /*Qx*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - Word16 *pF0, /*Q10*/ - Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ - Word16 *thresholdModification, /*Q10*/ + const Word32 powerSpectrum[], /*Qx*/ + const Word32 lastPitchLag, /*Qx*/ + const Word32 currentPitchLag, /*Qx*/ + Word16 *pF0, /*Q10*/ + Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ + Word16 *thresholdModification, /*Q10*/ Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ - const Word16 element_mode -) + const Word16 element_mode ) { Word16 pitchIsStable; Word16 origF0; -- GitLab From 833a2a297d66a4b15b807d2df4a787bf23bda04a Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 14:44:14 +0200 Subject: [PATCH 11/19] fix windows warning causing error --- lib_dec/TonalComponentDetection_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100644 new mode 100755 index fa9c9db7a..e77f68760 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -589,8 +589,8 @@ static void CorrectF0( const Word16 element_mode ) { Word16 /*short*/ i; - Word16 /*short*/ F0; - Word32 /*long*/ F0_32; /* unused in EVS_MONO */ + Word16 /*short*/ F0 = 0; /* init for windows compiler only */ + Word32 /*long*/ F0_32 = 0; /* unused in EVS_MONO */ Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ Word16 /*short*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; /*Q0*/ -- GitLab From f99936ace469dfd591784b226fb8631cd1bb4a7d Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 14:49:08 +0200 Subject: [PATCH 12/19] fix clang format --- lib_dec/TonalComponentDetection_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index e77f68760..ae163dfc7 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -589,7 +589,7 @@ static void CorrectF0( const Word16 element_mode ) { Word16 /*short*/ i; - Word16 /*short*/ F0 = 0; /* init for windows compiler only */ + Word16 /*short*/ F0 = 0; /* init for windows compiler only */ Word32 /*long*/ F0_32 = 0; /* unused in EVS_MONO */ Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ -- GitLab From 64768dfdb97cbf58ad9a69f48d13670b736fcbcb Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 16:15:53 +0200 Subject: [PATCH 13/19] fix memory sanitizer issue --- lib_dec/TonalComponentDetection_fx.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100644 new mode 100755 index ae163dfc7..f653a2118 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -1270,8 +1270,16 @@ static void RefineThresholdsUsingPitch_fx( GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, &origF0_32, pF0, pF0_32, element_mode ); - modifyThresholds( *pF0, *pF0_32, origF0, origF0_32, - thresholdModification, thresholdModification32, element_mode ); + IF( EQ_16( element_mode, EVS_MONO ) ) + { + modifyThresholds( *pF0, 0, origF0, origF0_32, + thresholdModification, thresholdModification32, element_mode ); + } + ELSE + { + modifyThresholds( 0, *pF0_32, origF0, origF0_32, + thresholdModification, thresholdModification32, element_mode ); + } } ELSE { -- GitLab From b0d4b78fe72f95c5176f39344d9de08b2f6a4468 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 16:31:31 +0200 Subject: [PATCH 14/19] deactivated macro FIX_ISSUE_1966 and changed code sequence to runtime code, that should be BE to EVS. Actually, this is a bug fix, that should be corrected in EVS. --- lib_com/options.h | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 86 +++++++++++++++++-------------- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index de46d7f22..f3700d8c8 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -133,7 +133,7 @@ #define FIX_1521_SBA_LOUDNESS_STEREO /* FhG: issue 1521: Fix loudness for SBA to stereo rendering */ #define FIX_1559 /* Eri/FhG: fix for Issue 1559 in FD CNG with bitrate/bw switching */ -#define FIX_ISSUE_1966 /* FhG: Basop issue 1966: shift phase range to [-2PI..+2PI[, handle 4 quadrants */ +/*#define FIX_ISSUE_1966*/ /* FhG: Basop issue 1966: shift phase range to [-2PI..+2PI[, handle 4 quadrants */ /* FhG: Basop issue 1966: use 32-bit variables for F0 and thresholdModification */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 335f978d8..c46334042 100755 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -23,7 +23,7 @@ static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 typ 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 ); 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 ); static void FindPhases( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp ); -static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[] ); +static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[], const Word16 element_mode ); /*******************************************************/ @@ -598,7 +598,8 @@ static void FindPhases( /* o: Phase difference [-pi;pi] 2Q13*/ static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, /* i : Pointer to internal structure */ - Word32 powerSpectrum[] ) /* i : Power spectrum data Qx */ + Word32 powerSpectrum[], /* i : Power spectrum data Qx */ + const Word16 element_mode ) { Word16 i, k; Word16 *phaseDiff; @@ -627,60 +628,65 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); -#ifdef FIX_ISSUE_1966 - if ( EQ_16( s_and( k, 3 ), 1 ) ) + IF( EQ_16 (element_mode, EVS_MONO ) ) { - phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; - move16(); - } - if ( EQ_16( s_and( k, 3 ), 2 ) ) - { - phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; - move16(); - } - if ( EQ_16( s_and( k, 3 ), 3 ) ) - { - phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; - move16(); - } - -#else - if ( s_and( k, 1 ) != 0 ) - { - phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; - move16(); + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; + move16(); + } } -#endif - } - ELSE - { - IF( GE_32( Mpy_32_16_1( powerSpectrum[k + 1], 512 /*1.0f Q9*/ ), Mpy_32_16_1( powerSpectrum[k - 1], MAXRATIO ) ) ) + ELSE { - phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ - move16(); -#ifdef FIX_ISSUE_1966 if ( EQ_16( s_and( k, 3 ), 1 ) ) { - phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; + phaseDiff[i] = 12868 /* 1*EVS_PI 3Q12*/; move16(); } if ( EQ_16( s_and( k, 3 ), 2 ) ) { - phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; + phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; move16(); } if ( EQ_16( s_and( k, 3 ), 3 ) ) { - phaseDiff[i] = 0 /* 0*EVS_PI 3Q12*/; + phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; move16(); } -#else - if ( s_and( k, 1 ) != 0 ) + } + } + ELSE + { + IF( GE_32( Mpy_32_16_1( powerSpectrum[k + 1], 512 /*1.0f Q9*/ ), Mpy_32_16_1( powerSpectrum[k - 1], MAXRATIO ) ) ) + { + phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ + move16(); + IF( EQ_16( element_mode, EVS_MONO ) ) { - phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ - move16(); + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ + move16(); + } + } + ELSE + { + if ( EQ_16( s_and( k, 3 ), 1 ) ) + { + phaseDiff[i] = -25736 /*-2*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 2 ) ) + { + phaseDiff[i] = -12868 /*-1*EVS_PI 3Q12*/; + move16(); + } + if ( EQ_16( s_and( k, 3 ), 3 ) ) + { + phaseDiff[i] = 0 /* 0*EVS_PI 3Q12*/; + move16(); + } } -#endif } ELSE { @@ -832,7 +838,7 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( floorPowerSpectrum, psychParamsCurrent, element_mode ); FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); - FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); + FindPhaseDifferences( hTonalMDCTConc, powerSpectrum, element_mode ); IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) { -- GitLab From ce589b019ec4088bad1f8df2336478a99da235f0 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 16:36:00 +0200 Subject: [PATCH 15/19] fix clang format --- lib_dec/tonalMDCTconcealment_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 lib_dec/tonalMDCTconcealment_fx.c diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c old mode 100755 new mode 100644 index c46334042..0834d987c --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -628,7 +628,7 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); - IF( EQ_16 (element_mode, EVS_MONO ) ) + IF( EQ_16( element_mode, EVS_MONO ) ) { if ( s_and( k, 1 ) != 0 ) { -- GitLab From d314b4b2920690d06d67d9d7a2245bcff4c7b827 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 17:08:46 +0200 Subject: [PATCH 16/19] fixed another msan issue when invoking modifyThresholds --- lib_dec/TonalComponentDetection_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index f653a2118..f97fe1ea7 100755 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -833,7 +833,7 @@ static void modifyThresholds( Word16 /*short*/ origF0, /*I - Q10*/ Word32 origF0_32, /*I - Q26*/ Word16 * /*short*/ thresholdModification, /*Q10*/ - Word32 * /*short*/ thresholdModification32, /*Q26*/ + Word32 * /*long*/ thresholdModification32, /*Q26*/ const Word16 element_mode ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; @@ -1272,12 +1272,12 @@ static void RefineThresholdsUsingPitch_fx( IF( EQ_16( element_mode, EVS_MONO ) ) { - modifyThresholds( *pF0, 0, origF0, origF0_32, + modifyThresholds( *pF0, 0, origF0, 0, thresholdModification, thresholdModification32, element_mode ); } ELSE { - modifyThresholds( 0, *pF0_32, origF0, origF0_32, + modifyThresholds( 0, *pF0_32, 0, origF0_32, thresholdModification, thresholdModification32, element_mode ); } } -- GitLab From c95b6c7b6682657e2f331acbb000dcfa420b6a57 Mon Sep 17 00:00:00 2001 From: Arthur Date: Tue, 5 May 2026 17:44:36 +0200 Subject: [PATCH 17/19] fix clang format --- lib_dec/TonalComponentDetection_fx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index f97fe1ea7..d822dba2b --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -828,13 +828,13 @@ static void modifyThreshold( static void modifyThresholds( - Word16 /*short*/ F0, /*I - Q10*/ - Word32 F0_32, /*I - Q26*/ - Word16 /*short*/ origF0, /*I - Q10*/ - Word32 origF0_32, /*I - Q26*/ - Word16 * /*short*/ thresholdModification, /*Q10*/ - Word32 * /*long*/ thresholdModification32, /*Q26*/ - const Word16 element_mode ) /*I/O - Q10*/ + Word16 /*short*/ F0, /*I - Q10*/ + Word32 F0_32, /*I - Q26*/ + Word16 /*short*/ origF0, /*I - Q10*/ + Word32 origF0_32, /*I - Q26*/ + Word16 * /*short*/ thresholdModification, /*Q10*/ + Word32 * /*long*/ thresholdModification32, /*Q26*/ + const Word16 element_mode ) /*I/O - Q10*/ { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; -- GitLab From c1c1eb5155a6d55620763aa4609702308839df5e Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 7 May 2026 16:33:01 +0200 Subject: [PATCH 18/19] encapsulated changes in two macros: FIX_ISSUE_19666_PHASE_DIFF andf FIX_ISSUE_1966_F0_32BIT --- lib_com/options.h | 7 +- lib_dec/TonalComponentDetection_fx.c | 280 +++++++++++++++++++++++---- lib_dec/tonalMDCTconcealment_fx.c | 37 +++- 3 files changed, 278 insertions(+), 46 deletions(-) mode change 100644 => 100755 lib_dec/TonalComponentDetection_fx.c mode change 100644 => 100755 lib_dec/tonalMDCTconcealment_fx.c diff --git a/lib_com/options.h b/lib_com/options.h index f3700d8c8..6a2f8f05f 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -133,8 +133,11 @@ #define FIX_1521_SBA_LOUDNESS_STEREO /* FhG: issue 1521: Fix loudness for SBA to stereo rendering */ #define FIX_1559 /* Eri/FhG: fix for Issue 1559 in FD CNG with bitrate/bw switching */ -/*#define FIX_ISSUE_1966*/ /* FhG: Basop issue 1966: shift phase range to [-2PI..+2PI[, handle 4 quadrants */ - /* FhG: Basop issue 1966: use 32-bit variables for F0 and thresholdModification */ +/* Macros for issue 1966 are independent, phase diff is always BE for EVS_MONO */ +/* The changes for F0+thdModification are mainly for IVAS better float compatibility, */ +/* for EVS_MONO, all is kept BE. */ +#define FIX_ISSUE_1966_PHASE_DIFF /* FhG: Basop issue 1966: shift phase range to [-2PI..+2PI[, handle 4 quadrants */ +#define FIX_ISSUE_1966_F0_32BIT /* FhG: Basop issue 1966: use 32-bit variables for F0 and thresholdModification */ /* ##################### End NON-BE switches ########################### */ /* ################## End MAINTENANCE switches ######################### */ diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100644 new mode 100755 index d822dba2b..50ba750de --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -24,14 +24,24 @@ 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, Word32 *const pOrigF0_32, Word16 *const pF0, Word32 *const pF0_32, const Word16 element_mode ); static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); +#ifdef FIX_ISSUE_1966_F0_32BIT +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word32 *const pOrigF0_32, Word16 *const pF0, Word32 *const pF0_32, const Word16 element_mode ); static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0, Word32 *pF0_32, const Word16 element_mode ); static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word32 *thresholdModificationNew32, Word16 floorPowerSpectrum, const Word16 element_mode ); static void modifyThreshold( Word16 i, Word16 F0, Word32 F0_32, Word16 threshold, Word32 threshold_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); static void modifyThresholds( Word16 F0, Word32 F0_32, Word16 origF0, Word32 origF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word32 *pF0_32, Word16 *thresholdModification, Word32 *thresholdModification32, const Word16 element_mode ); 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, Word32 *thresholdModification32, const Word16 element_mode ); +#else +static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); +static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); +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 ); +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, const Word16 element_mode ); +#endif /*-------------------------------------------------------------------* @@ -65,8 +75,10 @@ void DetectTonalComponents_fx( ) { Word16 F0; +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 F0_32; Word32 thresholdModification32[L_FRAME_MAX]; +#endif Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; Word32 pScaledMdctSpectrum[L_FRAME_MAX]; Word16 nBands; @@ -128,6 +140,7 @@ void DetectTonalComponents_fx( scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ } +#ifdef FIX_ISSUE_1966_F0_32BIT /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, thresholdModification32, floorPowerSpectrum, element_mode ); @@ -142,6 +155,17 @@ void DetectTonalComponents_fx( } findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, thresholdModification32, element_mode ); +#else + /* Find peak candidates in the last frame. */ + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum); + + /* Refine peak candidates using the pitch information */ + RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); + + /* Find peaks in the second last frame */ + findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, + F0, thresholdModification, element_mode ); +#endif return; } @@ -404,13 +428,18 @@ static void GetF0( Word16 /*short*/ const nSamples, /*i - Q0 */ Word16 /*short*/ const nSamplesCore, /*i - Q0 */ Word32 /*int*/ const *const powerSpectrum, - /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*int*/ const pitchLag, /*i - Q16*/ - Word16 /*short*/ *const pOrigF0, /*o - Q10*/ - Word32 *const pOrigF0_32, /*o - Q10+16*/ - Word16 /*short*/ *const pF0, /*o - Q10*/ - Word32 *const pF0_32, /*o - Q10+16*/ - const Word16 element_mode ) + /*i - Qx */ /*is justed handed over and given back*/ + Word32 /*int*/ const pitchLag, /*i - Q16*/ + Word16 /*short*/ *const pOrigF0, /*o - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + Word32 *const pOrigF0_32, /*o - Q10+16*/ +#endif + Word16 /*short*/ *const pF0 /*o - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + , Word32 *const pF0_32, /*o - Q10+16*/ + const Word16 element_mode /*i EVS_MONO or anything else */ +#endif + ) { Word16 /*short*/ tmpPitchLag; Word16 /*short*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; /*Q0*/ @@ -429,6 +458,7 @@ static void GetF0( = round_fx( L_shl( pitchLag, 4 ) ); /*no division by 2, will be done in following division - furthermore, do a leftshift before rounding, to preserve more accuracy - will be accommodated also in following division*/ +#ifdef FIX_ISSUE_1966_F0_32BIT IF( element_mode == EVS_MONO ) { /**pF0 = nSamplesCore/tmpPitchLag;*/ @@ -448,6 +478,14 @@ static void GetF0( *pOrigF0_32 = *pF0_32; /*Q26*/ move32(); } +#else + /**pF0 = nSamplesCore/tmpPitchLag;*/ + BASOP_Util_Divide_MantExp( nSamplesCore, 0, tmpPitchLag, -( 1 /*division by 2*/ + 4 /*accommodate accuracy-prevention-leftshift*/ ), pF0, &tmp ); /*pF0 is Q15*/ + *pF0 = shr_sat( *pF0, sub( 5, tmp ) ); /*Q10 without scalingfactor*/ + move16(); + *pOrigF0 = *pF0; /*Q10*/ + move16(); +#endif tmp = 2 * LAST_HARMONIC_POS_TO_CHECK; if ( LT_16( nSamples, 2 * LAST_HARMONIC_POS_TO_CHECK ) ) @@ -455,6 +493,8 @@ static void GetF0( move16(); tmp = nSamples; } + +#ifdef FIX_ISSUE_1966_F0_32BIT IF( element_mode == EVS_MONO ) { BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); @@ -472,9 +512,17 @@ static void GetF0( findStrongestHarmonics( nSamples, powerSpectrum, extract_h( *pF0_32 ), nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); CorrectF0( rgiStrongHarmonics, nStrongHarmonics, NULL, pF0_32, element_mode ); } +#else + BASOP_Util_Divide_MantExp( tmp, 15, *pF0, 5, &nTotalHarmonics, &tmp ); + nTotalHarmonics = shl( nTotalHarmonics, sub( tmp, 15 ) ); + /* Get in rgiStrongHarmonics all i for which i*F0 are the strongest harmonics */ + findStrongestHarmonics( nSamples, powerSpectrum, *pF0, nTotalHarmonics, rgiStrongHarmonics, &nStrongHarmonics ); + CorrectF0( rgiStrongHarmonics, nStrongHarmonics, pF0 ); +#endif } ELSE { +#ifdef FIX_ISSUE_1966_F0_32BIT IF( element_mode == EVS_MONO ) { move16(); @@ -489,6 +537,12 @@ static void GetF0( *pF0_32 = 0; *pOrigF0_32 = 0; } +#else + move16(); + move16(); + *pF0 = 0; + *pOrigF0 = 0; +#endif } return; @@ -584,13 +638,18 @@ static void findStrongestHarmonics( static void CorrectF0( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ - Word16 /*short*/ *pF0, /*I/O - Q10 range: {0}, [4..18) */ - Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ - const Word16 element_mode ) + Word16 /*short*/ *pF0 /*I/O - Q10 range: {0}, [4..18) */ +#ifdef FIX_ISSUE_1966_F0_32BIT + , Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ + const Word16 element_mode /*I EVS_MONO or anything else */ +#endif + ) { Word16 /*short*/ i; Word16 /*short*/ F0 = 0; /* init for windows compiler only */ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 /*long*/ F0_32 = 0; /* unused in EVS_MONO */ +#endif Word16 /*short*/ diff[MAX_PEAKS_FROM_PITCH - 1], sortedDiff[MAX_PEAKS_FROM_PITCH - 1]; /*Q0*/ Word16 /*short*/ iMostCommonDiff, nMostCommonDiff, nSameDiff, iMult; /*Q0*/ @@ -605,6 +664,7 @@ static void CorrectF0( move16(); } +#ifdef FIX_ISSUE_1966_F0_32BIT /* i = MAX_PEAKS_FROM_PITCH - 1 (9) now */ IF( element_mode == EVS_MONO ) { @@ -628,6 +688,17 @@ static void CorrectF0( move16(); } } +#else + F0 = *pF0; /*Q10*/ + move16(); + test(); + if ( F0 == 0 || nHarmonics == 0 ) + { + i = 0; /* skip processing */ + move16(); + } + +#endif IF( i != 0 ) /* skip processing, if F0=0 or nHarmonics=0 */ { @@ -732,6 +803,7 @@ static void CorrectF0( IF( LE_16( iMult, 3 ) ) { +#ifdef FIX_ISSUE_1966_F0_32BIT /* Use iMostCommonDiff, because the lowest pHarmonicIndexes[i] (which is equal to iMult) may not correspond to the new F0, but to it's multiple */ IF( element_mode == EVS_MONO ) { @@ -741,13 +813,28 @@ static void CorrectF0( { F0_32 = L_shl_sat( Mpy_32_16_1( F0_32 /*Q10+16*/, iMostCommonDiff /*Q0*/ ), 15 ); /*Q10+16*/ } +#else + F0 = round_fx_sat( L_shl_sat( L_mult( iMostCommonDiff /*Q0*/, F0 /*Q10*/ ), 15 ) ); /*Q10*/ +#endif } ELSE { +#ifdef FIX_ISSUE_1966_F0_32BIT + IF( element_mode == EVS_MONO ) + { + F0 = 0; + move16(); + } + ELSE + { + F0_32 = 0; + move32(); + } +#else F0 = 0; move16(); - F0_32 = 0; - move32(); +#endif + } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ @@ -758,12 +845,24 @@ static void CorrectF0( if ( ( GT_16( iMostCommonDiff, 1 ) ) || ( LT_16( nMostCommonDiff, 3 ) ) ) { /* Not enough peaks at the same distance => don't use the pitch. */ +#ifdef FIX_ISSUE_1966_F0_32BIT + IF( element_mode == EVS_MONO ) + { + F0 = 0; + move16(); + } + ELSE + { + F0_32 = 0; + move32(); + } +#else F0 = 0; move16(); - F0_32 = 0; - move32(); +#endif } } +#ifdef FIX_ISSUE_1966_F0_32BIT IF( element_mode == EVS_MONO ) { *pF0 = F0; @@ -774,6 +873,10 @@ static void CorrectF0( *pF0_32 = F0_32; move32(); } +#else + *pF0 = F0; + move16(); +#endif } return; } @@ -782,18 +885,26 @@ static void CorrectF0( static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ Word16 /*short*/ F0, /*I - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 F0_32, /*I - Q26*/ +#endif Word16 /*short*/ threshold, /*I - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 threshold_32, /*I - Q26*/ - Word16 * /*short*/ thresholdModification, /*I - Q10*/ - Word32 * /*long*/ thresholdModification32, /*I - Q26*/ - const Word16 element_mode ) /*I/O - Q10*/ +#endif + Word16 * /*short*/ thresholdModification /*I - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + , Word32 * /*long*/ thresholdModification32, /*I - Q26*/ + const Word16 element_mode /*I/O - Q10*/ +#endif + ) { Word32 harmonic; Word16 fractional /*Q15*/; Word16 k /*Q0*/; Word16 twoTimesFract /*Q10*/; +#ifdef FIX_ISSUE_1966_F0_32BIT IF( EQ_16( element_mode, EVS_MONO ) ) { harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ @@ -823,22 +934,43 @@ static void modifyThreshold( move32(); thresholdModification32[k + 1] = L_add( threshold_32 /*Q10+16*/, L_sub( 2048 << 16 /*2 in Q10+16*/, L_twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ } +#else + harmonic = L_mult( shl( i, 5 ), F0 ); /*Q0 * Q10 = 15Q16*/ + k = extract_h( harmonic ); /*Q0*/ + fractional = lshr( extract_l( harmonic ), 1 ); /* Fractional part of the i*F0 */ /*Q15*/ + twoTimesFract = mult( 2048 /*2 in Q10*/, fractional /*Q15*/ ); /*Q10*/ /* threshold if the center of the peek is between k-1 and k, threshold+2 if the center of the peek is between k and k+1 */ + + move16(); + thresholdModification[k] = threshold; + move16(); + thresholdModification[k - 1] = add( threshold /*Q10*/, twoTimesFract /*Q10*/ ); /*Q10*/ + move16(); + thresholdModification[k + 1] = add( threshold /*Q10*/, sub( 2048 /*2 in Q10*/, twoTimesFract /*Q10*/ ) /*Q10*/ ); /*Q10*/ +#endif return; } static void modifyThresholds( Word16 /*short*/ F0, /*I - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 F0_32, /*I - Q26*/ +#endif Word16 /*short*/ origF0, /*I - Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 origF0_32, /*I - Q26*/ - Word16 * /*short*/ thresholdModification, /*Q10*/ - Word32 * /*long*/ thresholdModification32, /*Q26*/ - const Word16 element_mode ) /*I/O - Q10*/ +#endif + Word16 * /*short*/ thresholdModification /*Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + , Word32 * /*long*/ thresholdModification32, /*Q26*/ + const Word16 element_mode /*I EVS_MONO or anything else */ +#endif + ) { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; +#ifdef FIX_ISSUE_1966_F0_32BIT /* Note: in case besides EVS_MONO, we set the 16-bit variables */ /* accordingly and control further processing with those. */ IF( element_mode != EVS_MONO ) @@ -846,6 +978,7 @@ static void modifyThresholds( origF0 = extract_h( origF0_32 ); F0 = extract_h( F0_32 ); } +#endif IF( origF0 > 0 ) { @@ -855,10 +988,14 @@ static void modifyThresholds( FOR( i = 1; i <= nHarmonics; i++ ) { +#ifdef FIX_ISSUE_1966_F0_32BIT modifyThreshold( i, origF0, origF0_32, 717 /*0.7f in Q10*/, 46976205 /*0.7f in Q10+16*/, thresholdModification, thresholdModification32, element_mode ); +#else + modifyThreshold( i, origF0, 717 /*0.7f in Q10*/, thresholdModification ); +#endif } } IF( F0 > 0 ) @@ -871,17 +1008,25 @@ static void modifyThresholds( FOR( i = tmp; i > 0; i-- ) { +#ifdef FIX_ISSUE_1966_F0_32BIT modifyThreshold( i, origF0, origF0_32, 358 /*0.35f in Q10*/, 23488102 /*0.35 in Q10+16*/, thresholdModification, thresholdModification32, element_mode ); +#else + modifyThreshold( i, origF0, 358 /*0.35f in Q10*/, thresholdModification ); +#endif } FOR( i = 1; i <= nHarmonics; i++ ) { +#ifdef FIX_ISSUE_1966_F0_32BIT modifyThreshold( i, F0, F0_32, 358 /*0.35f Q10*/, 23488102 /*0.35 in Q10+16*/, thresholdModification, thresholdModification32, element_mode ); +#else + modifyThreshold( i, F0, 358 /*0.35f Q10*/, thresholdModification ); +#endif } } } @@ -891,14 +1036,17 @@ static void modifyThresholds( static void findCandidates( - const Word16 nSamples, /* i : frame size */ - const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ - const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ - Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ - /* Note: the next array is only available if not in EVS_MONO mode */ - Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ - Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ - const Word16 element_mode /* i : EVS_MONO or anything else */ + const Word16 nSamples, /* i : frame size */ + const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ + const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ + Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ +#ifdef FIX_ISSUE_1966_F0_32BIT + Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ + Word16 floorPowerSpectrum, /* i : lower limit for powerspectrum bins Q0*/ + const Word16 element_mode /* i : EVS_MONO or anything else */ +#else + Word16 floorPowerSpectrum /* i : lower limit for powerspectrum bins Q0*/ +#endif ) { Word32 powerSpectrum[L_FRAME_MAX]; @@ -912,6 +1060,7 @@ static void findCandidates( calcPseudoSpec( MDCTSpectrum, MDCTSpectrum_exp, nSamples, floorPowerSpectrum, powerSpectrum, &powerSpectrum_exp ); getEnvelope( nSamples, powerSpectrum, 0, envelope, smoothedSpectrum ); +#ifdef FIX_ISSUE_1966_F0_32BIT IF( EQ_16( element_mode, EVS_MONO ) ) { set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ @@ -920,6 +1069,9 @@ static void findCandidates( { set32_fx( thresholdModificationNew32, ( UNREACHABLE_THRESHOLD ) << 16, nSamples ); /*Q10+Q16*/ } +#else + set16_fx( thresholdModificationNew, UNREACHABLE_THRESHOLD, nSamples ); /*Q10*/ +#endif k = GROUP_LENGTH / 2; move16(); @@ -1009,6 +1161,7 @@ static void findCandidates( /* Modify thresholds for the following frame */ tmp_loop3 = add( k, 2 ); +#ifdef FIX_ISSUE_1966_F0_32BIT IF( EQ_16( element_mode, EVS_MONO ) ) { FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) @@ -1037,6 +1190,19 @@ static void findCandidates( } } } +#else + FOR( j = sub( k, 1 ); j < tmp_loop3; j++ ) + { + thresholdModificationNew[j] = BIG_THRESHOLD; /*Q10*/ + move16(); + + if ( GT_32( smoothedSpectrum[j], envelope[j] ) ) + { + thresholdModificationNew[j] = SMALL_THRESHOLD; /*Q10*/ + move16(); + } + } +#endif /* Jump to the next foot of the peak. */ k = upperIdx; move16(); @@ -1050,17 +1216,19 @@ static void findCandidates( static void findTonalComponents_fx( - Word16 *indexOfTonalPeak, /* OUT Q0*/ - Word16 *lowerIndex, /* OUT Q0*/ - Word16 *upperIndex, /* OUT Q0*/ - Word16 *numIndexes, /* OUT Q0*/ - Word16 nSamples, /* IN */ - const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ + Word16 *indexOfTonalPeak, /* OUT Q0*/ + Word16 *lowerIndex, /* OUT Q0*/ + Word16 *upperIndex, /* OUT Q0*/ + Word16 *numIndexes, /* OUT Q0*/ + Word16 nSamples, /* IN Q0*/ + const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, - Word16 F0, /* IN */ - Word16 *thresholdModification, /* IN Q10*/ - Word32 *thresholdModification32, /* IN Q10+Q16, unused in EVS_MONO */ - const Word16 element_mode ) /* IN, EVS_MONO or anything else */ + Word16 F0, /* IN Q10*/ + Word16 *thresholdModification, /* IN Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + Word32 *thresholdModification32,/* IN Q10+Q16, unused in EVS_MONO */ +#endif + const Word16 element_mode ) /* IN, EVS_MONO or anything else */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -1091,6 +1259,10 @@ static void findTonalComponents_fx( } ELSE { +#ifdef FIX_ISSUE_1966_F0_32BIT + /* Note: This is the key code for the issue 1966. With 32-bit thresholds, the comparison */ + /* powerSpectrum[k] > envelope[k]*thresholdModification[k] is closer to float and the */ + /* variable numIndexes becomes a bit higher compared to (rounded) 16-bit thresholds. */ Word64 mult_64; Word16 lshift; Word16 mult_exp; @@ -1110,6 +1282,13 @@ static void findTonalComponents_fx( mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10 + 16, lshift ) ), 31 ) ); } flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); +#else + 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 ) ); + 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 */ @@ -1245,14 +1424,21 @@ static void RefineThresholdsUsingPitch_fx( const Word32 lastPitchLag, /*Qx*/ const Word32 currentPitchLag, /*Qx*/ Word16 *pF0, /*Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ - Word16 *thresholdModification, /*Q10*/ - Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ - const Word16 element_mode ) +#endif + Word16 *thresholdModification /*Q10*/ +#ifdef FIX_ISSUE_1966_F0_32BIT + , Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ + const Word16 element_mode /*Q0 EVS_MONO or anything else */ +#endif + ) { Word16 pitchIsStable; Word16 origF0; +#ifdef FIX_ISSUE_1966_F0_32BIT Word32 origF0_32; /* unused in EVS_MONO mode */ +#endif Word32 L_tmp; /*pitchIsStable = (fabs(lastPitchLag-currentPitchLag) < 0.25f);*/ @@ -1267,6 +1453,7 @@ static void RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { +#ifdef FIX_ISSUE_1966_F0_32BIT GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, &origF0_32, pF0, pF0_32, element_mode ); @@ -1280,9 +1467,14 @@ static void RefineThresholdsUsingPitch_fx( modifyThresholds( 0, *pF0_32, 0, origF0_32, thresholdModification, thresholdModification32, element_mode ); } +#else + GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0); + modifyThresholds( *pF0, origF0, thresholdModification ); +#endif } ELSE { +#ifdef FIX_ISSUE_1966_F0_32BIT IF( EQ_16( element_mode, EVS_MONO ) ) { *pF0 = 0; @@ -1293,6 +1485,10 @@ static void RefineThresholdsUsingPitch_fx( *pF0_32 = 0; move32(); } +#else + *pF0 = 0; + move16(); +#endif } return; diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c old mode 100644 new mode 100755 index 0834d987c..160c070b9 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -23,7 +23,11 @@ static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 typ 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 ); 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 ); static void FindPhases( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 secondLastMDCT[], Word32 secondLastMDST[], Word16 diff_exp ); +#ifdef FIX_ISSUE_1966_PHASE_DIFF static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[], const Word16 element_mode ); +#else +static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, Word32 powerSpectrum[] ); +#endif /*******************************************************/ @@ -598,8 +602,11 @@ static void FindPhases( /* o: Phase difference [-pi;pi] 2Q13*/ static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, /* i : Pointer to internal structure */ - Word32 powerSpectrum[], /* i : Power spectrum data Qx */ - const Word16 element_mode ) + Word32 powerSpectrum[] /* i : Power spectrum data Qx */ +#ifdef FIX_ISSUE_1966_PHASE_DIFF + , const Word16 element_mode /* i : EVS_MONO or anything else */ +#endif + ) { Word16 i, k; Word16 *phaseDiff; @@ -628,6 +635,11 @@ static void FindPhaseDifferences( { phaseDiff[i] = 0; /*(float)tan(0.0f*EVS_PI/bandwidth);*/ move16(); + +#ifdef FIX_ISSUE_1966_PHASE_DIFF + /* Note: This version is closer to the float reference, except */ + /* for the phase range. It is here [-2PI..+2PI[, while */ + /* in float it is [0..4PI[. */ IF( EQ_16( element_mode, EVS_MONO ) ) { if ( s_and( k, 1 ) != 0 ) @@ -654,6 +666,14 @@ static void FindPhaseDifferences( move16(); } } +#else + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; + move16(); + } + +#endif } ELSE { @@ -661,6 +681,8 @@ static void FindPhaseDifferences( { phaseDiff[i] = 12868 /*EVS_PI 3Q12*/; /*(float)tan(2.0f*PI/bandwidth);*/ move16(); + +#ifdef FIX_ISSUE_1966_PHASE_DIFF IF( EQ_16( element_mode, EVS_MONO ) ) { if ( s_and( k, 1 ) != 0 ) @@ -687,6 +709,13 @@ static void FindPhaseDifferences( move16(); } } +#else + if ( s_and( k, 1 ) != 0 ) + { + phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ + move16(); + } +#endif } ELSE { @@ -838,7 +867,11 @@ static void CalcPowerSpecAndDetectTonalComponents_fx( floorPowerSpectrum, psychParamsCurrent, element_mode ); FindPhases( hTonalMDCTConc, secondLastMDCT, secondLastMDST, sub( secondLastMDST_exp, secondLastMDCT_exp ) ); +#ifdef FIX_ISSUE_1966_PHASE_DIFF FindPhaseDifferences( hTonalMDCTConc, powerSpectrum, element_mode ); +#else + FindPhaseDifferences( hTonalMDCTConc, powerSpectrum ); +#endif IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) { -- GitLab From 3b8c063ffc2b6762f55cce450f4b3301d37ea7ab Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 7 May 2026 16:47:58 +0200 Subject: [PATCH 19/19] fix clang format --- lib_dec/TonalComponentDetection_fx.c | 110 ++++++++++++++------------- lib_dec/tonalMDCTconcealment_fx.c | 5 +- 2 files changed, 60 insertions(+), 55 deletions(-) mode change 100755 => 100644 lib_dec/TonalComponentDetection_fx.c mode change 100755 => 100644 lib_dec/tonalMDCTconcealment_fx.c diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c old mode 100755 new mode 100644 index 50ba750de..b5718956c --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -157,7 +157,7 @@ void DetectTonalComponents_fx( F0, thresholdModification, thresholdModification32, element_mode ); #else /* Find peak candidates in the last frame. */ - findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum); + findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); @@ -428,18 +428,19 @@ static void GetF0( Word16 /*short*/ const nSamples, /*i - Q0 */ Word16 /*short*/ const nSamplesCore, /*i - Q0 */ Word32 /*int*/ const *const powerSpectrum, - /*i - Qx */ /*is justed handed over and given back*/ - Word32 /*int*/ const pitchLag, /*i - Q16*/ - Word16 /*short*/ *const pOrigF0, /*o - Q10*/ + /*i - Qx */ /*is justed handed over and given back*/ + Word32 /*int*/ const pitchLag, /*i - Q16*/ + Word16 /*short*/ *const pOrigF0, /*o - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 *const pOrigF0_32, /*o - Q10+16*/ + Word32 *const pOrigF0_32, /*o - Q10+16*/ #endif - Word16 /*short*/ *const pF0 /*o - Q10*/ + Word16 /*short*/ *const pF0 /*o - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - , Word32 *const pF0_32, /*o - Q10+16*/ - const Word16 element_mode /*i EVS_MONO or anything else */ + , + Word32 *const pF0_32, /*o - Q10+16*/ + const Word16 element_mode /*i EVS_MONO or anything else */ #endif - ) +) { Word16 /*short*/ tmpPitchLag; Word16 /*short*/ rgiStrongHarmonics[MAX_PEAKS_FROM_PITCH]; /*Q0*/ @@ -640,13 +641,14 @@ static void CorrectF0( const Word16 /*short*/ nHarmonics, /*I - Q0 */ Word16 /*short*/ *pF0 /*I/O - Q10 range: {0}, [4..18) */ #ifdef FIX_ISSUE_1966_F0_32BIT - , Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ - const Word16 element_mode /*I EVS_MONO or anything else */ + , + Word32 /*long*/ *pF0_32, /*I/O - Q10+16 range: {0}, [4..18), NULL for EVS_MONO */ + const Word16 element_mode /*I EVS_MONO or anything else */ #endif - ) +) { Word16 /*short*/ i; - Word16 /*short*/ F0 = 0; /* init for windows compiler only */ + Word16 /*short*/ F0 = 0; /* init for windows compiler only */ #ifdef FIX_ISSUE_1966_F0_32BIT Word32 /*long*/ F0_32 = 0; /* unused in EVS_MONO */ #endif @@ -834,7 +836,6 @@ static void CorrectF0( F0 = 0; move16(); #endif - } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ @@ -883,21 +884,22 @@ static void CorrectF0( static void modifyThreshold( - Word16 /*short*/ i, /*I - Q0 */ - Word16 /*short*/ F0, /*I - Q10*/ + Word16 /*short*/ i, /*I - Q0 */ + Word16 /*short*/ F0, /*I - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 F0_32, /*I - Q26*/ + Word32 F0_32, /*I - Q26*/ #endif - Word16 /*short*/ threshold, /*I - Q10*/ + Word16 /*short*/ threshold, /*I - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 threshold_32, /*I - Q26*/ + Word32 threshold_32, /*I - Q26*/ #endif - Word16 * /*short*/ thresholdModification /*I - Q10*/ + Word16 * /*short*/ thresholdModification /*I - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - , Word32 * /*long*/ thresholdModification32, /*I - Q26*/ + , + Word32 * /*long*/ thresholdModification32, /*I - Q26*/ const Word16 element_mode /*I/O - Q10*/ #endif - ) +) { Word32 harmonic; Word16 fractional /*Q15*/; @@ -952,20 +954,21 @@ static void modifyThreshold( static void modifyThresholds( - Word16 /*short*/ F0, /*I - Q10*/ + Word16 /*short*/ F0, /*I - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 F0_32, /*I - Q26*/ + Word32 F0_32, /*I - Q26*/ #endif - Word16 /*short*/ origF0, /*I - Q10*/ + Word16 /*short*/ origF0, /*I - Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 origF0_32, /*I - Q26*/ + Word32 origF0_32, /*I - Q26*/ #endif - Word16 * /*short*/ thresholdModification /*Q10*/ + Word16 * /*short*/ thresholdModification /*Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - , Word32 * /*long*/ thresholdModification32, /*Q26*/ + , + Word32 * /*long*/ thresholdModification32, /*Q26*/ const Word16 element_mode /*I EVS_MONO or anything else */ #endif - ) +) { Word16 /*int*/ i, /*int*/ nHarmonics; Word16 tmp, tmpM, tmpE; @@ -1036,16 +1039,16 @@ static void modifyThresholds( static void findCandidates( - const Word16 nSamples, /* i : frame size */ - const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ - const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ - Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ + const Word16 nSamples, /* i : frame size */ + const Word32 *MDCTSpectrum, /* i : MDCT spectrum */ + const Word16 MDCTSpectrum_exp, /* i : exponent of MDCT spectrum */ + Word16 *thresholdModificationNew, /* o : threshold modification Q10 */ #ifdef FIX_ISSUE_1966_F0_32BIT Word32 *thresholdModificationNew32, /* o : threshold modification Q10+Q16 */ Word16 floorPowerSpectrum, /* i : lower limit for powerspectrum bins Q0*/ const Word16 element_mode /* i : EVS_MONO or anything else */ #else - Word16 floorPowerSpectrum /* i : lower limit for powerspectrum bins Q0*/ + Word16 floorPowerSpectrum /* i : lower limit for powerspectrum bins Q0*/ #endif ) { @@ -1216,19 +1219,19 @@ static void findCandidates( static void findTonalComponents_fx( - Word16 *indexOfTonalPeak, /* OUT Q0*/ - Word16 *lowerIndex, /* OUT Q0*/ - Word16 *upperIndex, /* OUT Q0*/ - Word16 *numIndexes, /* OUT Q0*/ - Word16 nSamples, /* IN Q0*/ - const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ + Word16 *indexOfTonalPeak, /* OUT Q0*/ + Word16 *lowerIndex, /* OUT Q0*/ + Word16 *upperIndex, /* OUT Q0*/ + Word16 *numIndexes, /* OUT Q0*/ + Word16 nSamples, /* IN Q0*/ + const Word32 *powerSpectrum, /* IN Q31-powerSpectrum_e*/ const Word16 powerSpectrum_e, - Word16 F0, /* IN Q10*/ - Word16 *thresholdModification, /* IN Q10*/ + Word16 F0, /* IN Q10*/ + Word16 *thresholdModification, /* IN Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 *thresholdModification32,/* IN Q10+Q16, unused in EVS_MONO */ + Word32 *thresholdModification32, /* IN Q10+Q16, unused in EVS_MONO */ #endif - const Word16 element_mode ) /* IN, EVS_MONO or anything else */ + const Word16 element_mode ) /* IN, EVS_MONO or anything else */ { Word32 envelope[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ Word32 smoothedSpectrum[L_FRAME_MAX]; /*powerSpec_exp + LEVEL_EXP*/ @@ -1420,19 +1423,20 @@ static void findTonalComponents_fx( static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, - const Word32 powerSpectrum[], /*Qx*/ - const Word32 lastPitchLag, /*Qx*/ - const Word32 currentPitchLag, /*Qx*/ - Word16 *pF0, /*Q10*/ + const Word32 powerSpectrum[], /*Qx*/ + const Word32 lastPitchLag, /*Qx*/ + const Word32 currentPitchLag, /*Qx*/ + Word16 *pF0, /*Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ + Word32 *pF0_32, /*Q10+Q16, NULL in EVS_MONO mode */ #endif - Word16 *thresholdModification /*Q10*/ + Word16 *thresholdModification /*Q10*/ #ifdef FIX_ISSUE_1966_F0_32BIT - , Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ + , + Word32 *thresholdModification32, /*Q10+Q16, NULL in EVS_MONO mode */ const Word16 element_mode /*Q0 EVS_MONO or anything else */ #endif - ) +) { Word16 pitchIsStable; Word16 origF0; @@ -1468,7 +1472,7 @@ static void RefineThresholdsUsingPitch_fx( thresholdModification, thresholdModification32, element_mode ); } #else - GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0); + GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); modifyThresholds( *pF0, origF0, thresholdModification ); #endif } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c old mode 100755 new mode 100644 index 160c070b9..ae55088c0 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -604,9 +604,10 @@ static void FindPhaseDifferences( TonalMDCTConcealPtr const hTonalMDCTConc, /* i : Pointer to internal structure */ Word32 powerSpectrum[] /* i : Power spectrum data Qx */ #ifdef FIX_ISSUE_1966_PHASE_DIFF - , const Word16 element_mode /* i : EVS_MONO or anything else */ + , + const Word16 element_mode /* i : EVS_MONO or anything else */ #endif - ) +) { Word16 i, k; Word16 *phaseDiff; -- GitLab