Loading lib_com/ivas_prot_fx.h +2 −1 Original line number Diff line number Diff line Loading @@ -1896,6 +1896,7 @@ Word16 GetPLCModeDecision_ivas_fx( ); #endif // !HARMONIZE_2427_GETPLC #ifndef HARMONIZE_FUNC void ivas_DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Loading @@ -1916,7 +1917,7 @@ void ivas_DetectTonalComponents_fx( const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ); #endif ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ const Word32 element_brate, /* i : element bitrate */ Loading lib_com/options.h +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define FIX_MDCT_STEREO_ENC_STACK /* VA: basop issue 2428: Move IGF temporary buffers out of the highest stack */ #define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ /* #################### End BE switches ################################## */ Loading lib_com/prot_fx.h +33 −4 Original line number Diff line number Diff line Loading @@ -2298,6 +2298,7 @@ void E_UTIL_synthesis_fx( const Word16 update, const Word16 m ); #ifndef HARMONIZE_FUNC void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Loading @@ -2307,15 +2308,18 @@ void synth_mem_updt2( Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec /* i : flag for decoder indication */ ); void ivas_synth_mem_updt2_fx( #else void synth_mem_updt2_fx( #endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer */ Word16 mem_syn_r[], /* i/o: synthesis filter memory */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec ); const Word16 dec /* i : flag for decoder indication */ ); void lerp( const Word16 *f, Loading Loading @@ -5892,6 +5896,27 @@ void concealment_signal_tuning_fx( Word16 *outx_new_fx /*Qoutx_new_fx*/, const Word16 past_core ); #ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], Word16 *pNumIndexes, const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], const Word16 lastMDCTSpectrum_exp, const Word16 scaleFactors[], const Word16 scaleFactors_exp[], const Word16 scaleFactors_max_e, const Word32 secondLastPowerSpectrum[], const Word16 secondLastPowerSpectrum_e, const Word16 nSamples, const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins */ const PsychoacousticParameters *psychParamsCurrent, const Word16 element_mode ); #else void DetectTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Loading Loading @@ -5929,8 +5954,13 @@ void RefineTonalComponents( const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode ); #endif #ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( #else void ivas_RefineTonalComponents_fx( #endif Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], Loading @@ -5949,7 +5979,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode, const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ); ivas_error PsychoacousticParameters_Init( Loading Loading @@ -10717,7 +10747,6 @@ void UnmapIndex_fx( Word32 *Lag /* Q0 */ ); // #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) #define GET_ADJ2( T, L, F ) ( sub( shl( L, F ), T ) ) Word32 tcx_hm_render_fx( Loading lib_com/syn_filt_fx.c +11 −1 Original line number Diff line number Diff line Loading @@ -548,14 +548,19 @@ void E_UTIL_synthesis_fx( * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching *--------------------------------------------------------------------*/ #ifdef HARMONIZE_FUNC void synth_mem_updt2_fx( #else void ivas_synth_mem_updt2_fx( #endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ const Word16 dec ) const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; Word32 en1, en2; Loading Loading @@ -622,7 +627,11 @@ void ivas_synth_mem_updt2_fx( { Copy( mem_syn2, mem_syn, M ); } return; } #ifndef HARMONIZE_FUNC void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Loading Loading @@ -660,3 +669,4 @@ void synth_mem_updt2( Copy( mem_syn2, mem_syn, M ); } } #endif lib_dec/TonalComponentDetection_fx.c +124 −46 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #define _USE_MATH_DEFINES #include <assert.h> #include <stdint.h> #include "options.h" Loading @@ -14,23 +12,35 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); #ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); #endif static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); #ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); #endif static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); #ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); #else static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void ivas_RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); #endif /*-------------------------------------------------------------------* * DetectTonalComponents() Loading @@ -41,7 +51,11 @@ static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lower * pNumIndexes accordingly. *-------------------------------------------------------------------*/ #ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( #else void ivas_DetectTonalComponents_fx( #endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ Loading @@ -59,7 +73,11 @@ void ivas_DetectTonalComponents_fx( const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ const PsychoacousticParameters *psychParamsCurrent, #ifdef HARMONIZE_FUNC const Word16 element_mode /* i : element mode */ #else Word16 element_mode /* i : element mode */ #endif ) { Word16 F0; Loading @@ -71,6 +89,16 @@ void ivas_DetectTonalComponents_fx( set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); #ifdef HARMONIZE_FUNC IF( element_mode == EVS_MONO ) { mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); } ELSE #endif { FOR( Word16 i = 0; i < nSamples; i++ ) { pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ Loading Loading @@ -112,19 +140,29 @@ void ivas_DetectTonalComponents_fx( /* Guard bit */ lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ } /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ #ifdef HARMONIZE_FUNC RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); #else ivas_RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); #endif /* Find peaks in the second last frame */ #ifdef HARMONIZE_FUNC findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); #else ivas_findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); #endif return; } #ifndef HARMONIZE_FUNC void DetectTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Loading Loading @@ -162,6 +200,7 @@ void DetectTonalComponents( return; } #endif /*-------------------------------------------------------------------* * RefineTonalComponents() Loading @@ -173,6 +212,7 @@ void DetectTonalComponents( * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ #ifndef HARMONIZE_FUNC void RefineTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Loading Loading @@ -258,8 +298,13 @@ void RefineTonalComponents( return; } #endif #ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( #else void ivas_RefineTonalComponents_fx( #endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ Loading @@ -278,7 +323,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ Word16 element_mode, const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ) { Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; /*Q0*/ Loading @@ -288,9 +333,15 @@ void ivas_RefineTonalComponents_fx( Word16 iNew, iOld, j; Word16 *pOldPhase, *pNewPhase; #ifdef HARMONIZE_FUNC DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #else ivas_DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #endif nPreservedPeaks = 0; move16(); Loading Loading @@ -561,7 +612,7 @@ static void GetF0( return; } #ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 /*short*/ const nSamples, /*i - Q0 */ Word16 /*short*/ const nSamplesCore, /*i - Q0 */ Loading Loading @@ -620,7 +671,7 @@ static void ivas_GetF0_fx( return; } #endif static void findStrongestHarmonics( const Word16 nSamples, Loading Loading @@ -703,6 +754,7 @@ static void findStrongestHarmonics( *pnHarmonics = nPeaks; /*Q0*/ move16(); return; } Loading Loading @@ -853,7 +905,7 @@ static void CorrectF0( return; } #ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ Loading Loading @@ -1007,7 +1059,7 @@ static void ivas_CorrectF0_fx( return; } #endif static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ Loading Loading @@ -1211,7 +1263,7 @@ static void findCandidates( return; } #ifndef HARMONIZE_FUNC static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, Loading Loading @@ -1252,9 +1304,13 @@ static void RefineThresholdsUsingPitch( return; } #endif #ifdef HARMONIZE_FUNC static void findTonalComponents_fx( #else static void ivas_findTonalComponents_fx( #endif Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Word16 *upperIndex, /* OUT Q0*/ Loading Loading @@ -1287,11 +1343,27 @@ static void ivas_findTonalComponents_fx( tmp_loop2 = sub( nSamples, 1 ); WHILE( LE_16( k, tmp_loop1 ) ) { #ifdef HARMONIZE_FUNC Word16 flag = 0; IF( element_mode == EVS_MONO && GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) { flag = 1; move16(); } ELSE { #endif Word64 mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 Word16 lshift = W_norm( mult_64 ); Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); #ifdef HARMONIZE_FUNC flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); } #else Word16 flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); #endif /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ IF( EQ_16( flag, 1 ) ) { Loading Loading @@ -1418,8 +1490,11 @@ static void ivas_findTonalComponents_fx( return; } #ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( #else static void ivas_RefineThresholdsUsingPitch_fx( #endif const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], /*Qx*/ Loading @@ -1445,9 +1520,13 @@ static void ivas_RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { #ifdef HARMONIZE_FUNC GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); #else ivas_GetF0_fx( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); #endif modifyThresholds( *pF0, origF0, thresholdModification ); } Loading @@ -1460,7 +1539,6 @@ static void ivas_RefineThresholdsUsingPitch_fx( return; } static void findTonalComponents( Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Loading Loading
lib_com/ivas_prot_fx.h +2 −1 Original line number Diff line number Diff line Loading @@ -1896,6 +1896,7 @@ Word16 GetPLCModeDecision_ivas_fx( ); #endif // !HARMONIZE_2427_GETPLC #ifndef HARMONIZE_FUNC void ivas_DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Loading @@ -1916,7 +1917,7 @@ void ivas_DetectTonalComponents_fx( const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ); #endif ivas_error stereo_dft_dec_create_fx( STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ const Word32 element_brate, /* i : element bitrate */ Loading
lib_com/options.h +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define FIX_MDCT_STEREO_ENC_STACK /* VA: basop issue 2428: Move IGF temporary buffers out of the highest stack */ #define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ /* #################### End BE switches ################################## */ Loading
lib_com/prot_fx.h +33 −4 Original line number Diff line number Diff line Loading @@ -2298,6 +2298,7 @@ void E_UTIL_synthesis_fx( const Word16 update, const Word16 m ); #ifndef HARMONIZE_FUNC void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Loading @@ -2307,15 +2308,18 @@ void synth_mem_updt2( Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec /* i : flag for decoder indication */ ); void ivas_synth_mem_updt2_fx( #else void synth_mem_updt2_fx( #endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer */ Word16 mem_syn_r[], /* i/o: synthesis filter memory */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec ); const Word16 dec /* i : flag for decoder indication */ ); void lerp( const Word16 *f, Loading Loading @@ -5892,6 +5896,27 @@ void concealment_signal_tuning_fx( Word16 *outx_new_fx /*Qoutx_new_fx*/, const Word16 past_core ); #ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], Word16 *pNumIndexes, const Word32 lastPitchLag, const Word32 currentPitchLag, const Word16 lastMDCTSpectrum[], const Word16 lastMDCTSpectrum_exp, const Word16 scaleFactors[], const Word16 scaleFactors_exp[], const Word16 scaleFactors_max_e, const Word32 secondLastPowerSpectrum[], const Word16 secondLastPowerSpectrum_e, const Word16 nSamples, const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins */ const PsychoacousticParameters *psychParamsCurrent, const Word16 element_mode ); #else void DetectTonalComponents( Word16 indexOfTonalPeak[], Word16 lowerIndex[], Loading Loading @@ -5929,8 +5954,13 @@ void RefineTonalComponents( const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode ); #endif #ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( #else void ivas_RefineTonalComponents_fx( #endif Word16 indexOfTonalPeak[], Word16 lowerIndex[], Word16 upperIndex[], Loading @@ -5949,7 +5979,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i: lower limit for power spectrum bins */ Word16 element_mode, const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ); ivas_error PsychoacousticParameters_Init( Loading Loading @@ -10717,7 +10747,6 @@ void UnmapIndex_fx( Word32 *Lag /* Q0 */ ); // #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) #define GET_ADJ2( T, L, F ) ( sub( shl( L, F ), T ) ) Word32 tcx_hm_render_fx( Loading
lib_com/syn_filt_fx.c +11 −1 Original line number Diff line number Diff line Loading @@ -548,14 +548,19 @@ void E_UTIL_synthesis_fx( * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching *--------------------------------------------------------------------*/ #ifdef HARMONIZE_FUNC void synth_mem_updt2_fx( #else void ivas_synth_mem_updt2_fx( #endif const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Word16 old_exc[], /* i/o: excitation buffer st->Q_syn */ Word16 mem_syn_r[], /* i/o: synthesis filter memory st->Q_syn */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target st->Q_syn */ Word16 mem_syn[], /* o : synthesis filter memory for find_target st->Q_syn */ const Word16 dec ) const Word16 dec /* i : flag for decoder indication */ ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; Word32 en1, en2; Loading Loading @@ -622,7 +627,11 @@ void ivas_synth_mem_updt2_fx( { Copy( mem_syn2, mem_syn, M ); } return; } #ifndef HARMONIZE_FUNC void synth_mem_updt2( const Word16 L_frame, /* i : frame length */ const Word16 last_L_frame, /* i : frame length */ Loading Loading @@ -660,3 +669,4 @@ void synth_mem_updt2( Copy( mem_syn2, mem_syn, M ); } } #endif
lib_dec/TonalComponentDetection_fx.c +124 −46 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ #define _USE_MATH_DEFINES #include <assert.h> #include <stdint.h> #include "options.h" Loading @@ -14,23 +12,35 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ static void calcPseudoSpec( const Word32 *mdctSpec, const Word16 mdctSpec_exp, const Word16 nSamples, Word16 floorPowerSpectrum, Word32 *powerSpec, Word16 *powerSpec_exp ); static void getEnvelope( const Word16 nSamples, const Word32 *powerSpec, Word16 F0, Word32 *envelope, Word32 *smoothedSpectrum ); static void GetF0( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); #ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 const nSamples, Word16 const nSamplesCore, Word32 const *const powerSpectrum, Word32 const pitchLag, Word16 *const pOrigF0, Word16 *const pF0 ); #endif static void findStrongestHarmonics( const Word16 nSamples, const Word32 *powerSpectrum, const Word16 F0, const Word16 nTotalHarmonics, Word16 *pHarmonicIndexes, Word16 *pnHarmonics ); static void CorrectF0( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); #ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 *pHarmonicIndexes, const Word16 nHarmonics, Word16 *pF0 ); #endif static void findCandidates( const Word16 nSamples, const Word32 *MDCTSpectrum, const Word16 MDCTSpectrum_exp, Word16 *thresholdModificationNew, Word16 floorPowerSpectrum ); static void modifyThreshold( Word16 i, Word16 F0, Word16 threshold, Word16 *thresholdModification ); static void modifyThresholds( Word16 F0, Word16 origF0, Word16 *thresholdModification ); #ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); #else static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void ivas_RefineThresholdsUsingPitch_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], const Word32 lastPitchLag, const Word32 currentPitchLag, Word16 *pF0, Word16 *thresholdModification ); static void findTonalComponents( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lowerIndex, Word16 *upperIndex, Word16 *numIndexes, Word16 nSamples, const Word32 *powerSpectrum, const Word16 powerSpectrum_e, Word16 F0, Word16 *thresholdModification, Word16 element_mode ); #endif /*-------------------------------------------------------------------* * DetectTonalComponents() Loading @@ -41,7 +51,11 @@ static void ivas_findTonalComponents_fx( Word16 *indexOfTonalPeak, Word16 *lower * pNumIndexes accordingly. *-------------------------------------------------------------------*/ #ifdef HARMONIZE_FUNC void DetectTonalComponents_fx( #else void ivas_DetectTonalComponents_fx( #endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ Loading @@ -59,7 +73,11 @@ void ivas_DetectTonalComponents_fx( const Word16 nSamplesCore, Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ const PsychoacousticParameters *psychParamsCurrent, #ifdef HARMONIZE_FUNC const Word16 element_mode /* i : element mode */ #else Word16 element_mode /* i : element mode */ #endif ) { Word16 F0; Loading @@ -71,6 +89,16 @@ void ivas_DetectTonalComponents_fx( set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); #ifdef HARMONIZE_FUNC IF( element_mode == EVS_MONO ) { mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); lastMDCTSpect_exp = add( lastMDCTSpectrum_exp, scaleFactors_max_e ); } ELSE #endif { FOR( Word16 i = 0; i < nSamples; i++ ) { pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); /*15-lastMDCTSpectrum_exp+16 -> 31 - lastMDCTSpectrum_exp*/ Loading Loading @@ -112,19 +140,29 @@ void ivas_DetectTonalComponents_fx( /* Guard bit */ lastMDCTSpect_exp = add( lastMDCTSpect_exp, 1 ); scale_sig32( pScaledMdctSpectrum, nSamples, -1 ); /*q_pScaledMdctSpectrum - 1*/ } /* Find peak candidates in the last frame. */ findCandidates( nSamples, pScaledMdctSpectrum, lastMDCTSpect_exp, thresholdModification, floorPowerSpectrum ); /* Refine peak candidates using the pitch information */ #ifdef HARMONIZE_FUNC RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); #else ivas_RefineThresholdsUsingPitch_fx( nSamples, nSamplesCore, secondLastPowerSpectrum, lastPitchLag, currentPitchLag, &F0, thresholdModification ); #endif /* Find peaks in the second last frame */ #ifdef HARMONIZE_FUNC findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); #else ivas_findTonalComponents_fx( indexOfTonalPeak, lowerIndex, upperIndex, pNumIndexes, nSamples, secondLastPowerSpectrum, secondLastPowerSpectrum_e, F0, thresholdModification, element_mode ); #endif return; } #ifndef HARMONIZE_FUNC void DetectTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Loading Loading @@ -162,6 +200,7 @@ void DetectTonalComponents( return; } #endif /*-------------------------------------------------------------------* * RefineTonalComponents() Loading @@ -173,6 +212,7 @@ void DetectTonalComponents( * then keep in indexOfTonalPeak only the tonal components that are * again detected Updates indexOfTonalPeak, lowerIndex, upperIndex, * phaseDiff, phases, pNumIndexes accordingly. */ #ifndef HARMONIZE_FUNC void RefineTonalComponents( Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Loading Loading @@ -258,8 +298,13 @@ void RefineTonalComponents( return; } #endif #ifdef HARMONIZE_FUNC void RefineTonalComponents_fx( #else void ivas_RefineTonalComponents_fx( #endif Word16 indexOfTonalPeak[], /*Q0*/ Word16 lowerIndex[], /*Q0*/ Word16 upperIndex[], /*Q0*/ Loading @@ -278,7 +323,7 @@ void ivas_RefineTonalComponents_fx( const Word16 nSamples, const Word16 nSamplesCore, const Word16 floorPowerSpectrum, /* i : lower limit for power spectrum bins Q0*/ Word16 element_mode, const Word16 element_mode, const PsychoacousticParameters *psychParamsCurrent ) { Word16 newIndexOfTonalPeak[MAX_NUMBER_OF_IDX]; /*Q0*/ Loading @@ -288,9 +333,15 @@ void ivas_RefineTonalComponents_fx( Word16 iNew, iOld, j; Word16 *pOldPhase, *pNewPhase; #ifdef HARMONIZE_FUNC DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #else ivas_DetectTonalComponents_fx( newIndexOfTonalPeak, newLowerIndex, newUpperIndex, &newNumIndexes, lastPitchLag, currentPitchLag, lastMDCTSpectrum, lastMDCTSpectrum_exp, scaleFactors, scaleFactors_exp, scaleFactors_max_e, secondLastPowerSpectrum, secondLastPowerSpectrum_e, nSamples, nSamplesCore, floorPowerSpectrum, psychParamsCurrent, element_mode ); #endif nPreservedPeaks = 0; move16(); Loading Loading @@ -561,7 +612,7 @@ static void GetF0( return; } #ifndef HARMONIZE_FUNC static void ivas_GetF0_fx( Word16 /*short*/ const nSamples, /*i - Q0 */ Word16 /*short*/ const nSamplesCore, /*i - Q0 */ Loading Loading @@ -620,7 +671,7 @@ static void ivas_GetF0_fx( return; } #endif static void findStrongestHarmonics( const Word16 nSamples, Loading Loading @@ -703,6 +754,7 @@ static void findStrongestHarmonics( *pnHarmonics = nPeaks; /*Q0*/ move16(); return; } Loading Loading @@ -853,7 +905,7 @@ static void CorrectF0( return; } #ifndef HARMONIZE_FUNC static void ivas_CorrectF0_fx( const Word16 /*short*/ *pHarmonicIndexes, /*I - Q0 */ const Word16 /*short*/ nHarmonics, /*I - Q0 */ Loading Loading @@ -1007,7 +1059,7 @@ static void ivas_CorrectF0_fx( return; } #endif static void modifyThreshold( Word16 /*short*/ i, /*I - Q0 */ Loading Loading @@ -1211,7 +1263,7 @@ static void findCandidates( return; } #ifndef HARMONIZE_FUNC static void RefineThresholdsUsingPitch( const Word16 nSamples, const Word16 nSamplesCore, Loading Loading @@ -1252,9 +1304,13 @@ static void RefineThresholdsUsingPitch( return; } #endif #ifdef HARMONIZE_FUNC static void findTonalComponents_fx( #else static void ivas_findTonalComponents_fx( #endif Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Word16 *upperIndex, /* OUT Q0*/ Loading Loading @@ -1287,11 +1343,27 @@ static void ivas_findTonalComponents_fx( tmp_loop2 = sub( nSamples, 1 ); WHILE( LE_16( k, tmp_loop1 ) ) { #ifdef HARMONIZE_FUNC Word16 flag = 0; IF( element_mode == EVS_MONO && GT_32( L_shr( smoothedSpectrum[k], 1 ), L_shl( Mpy_32_16_1( envelope[k] /*Q28,powerSpec_exp*/, thresholdModification[k] /*Q10*/ ), 4 ) ) ) { flag = 1; move16(); } ELSE { #endif Word64 mult_64 = W_mult_32_16( envelope[k], thresholdModification[k] ); // (Q31-(powerSpectrum_e+LEVEL_EXP))+1+10 Word16 lshift = W_norm( mult_64 ); Word32 mult_32 = W_extract_h( W_shl( mult_64, lshift ) ); //(Q31-(powerSpectrum_e+LEVEL_EXP) + lshift )+11 -32 Word16 mult_exp = sub( Q31, sub( add( sub( Q31, add( powerSpectrum_e, LEVEL_EXP ) ), add( 10, lshift ) ), 31 ) ); #ifdef HARMONIZE_FUNC flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); } #else Word16 flag = BASOP_Util_Cmp_Mant32Exp( smoothedSpectrum[k], ( powerSpectrum_e + LEVEL_EXP ), mult_32, mult_exp ); #endif /* There is 3 bits headroom in envelope and max of thresholdModification is 16384, so shifting left for 4 would produce overflow only when the result is anyhow close to 1 */ IF( EQ_16( flag, 1 ) ) { Loading Loading @@ -1418,8 +1490,11 @@ static void ivas_findTonalComponents_fx( return; } #ifdef HARMONIZE_FUNC static void RefineThresholdsUsingPitch_fx( #else static void ivas_RefineThresholdsUsingPitch_fx( #endif const Word16 nSamples, const Word16 nSamplesCore, const Word32 powerSpectrum[], /*Qx*/ Loading @@ -1445,9 +1520,13 @@ static void ivas_RefineThresholdsUsingPitch_fx( IF( pitchIsStable ) { #ifdef HARMONIZE_FUNC GetF0( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); #else ivas_GetF0_fx( nSamples, nSamplesCore, powerSpectrum, lastPitchLag, &origF0, pF0 ); #endif modifyThresholds( *pF0, origF0, thresholdModification ); } Loading @@ -1460,7 +1539,6 @@ static void ivas_RefineThresholdsUsingPitch_fx( return; } static void findTonalComponents( Word16 *indexOfTonalPeak, /* OUT Q0*/ Word16 *lowerIndex, /* OUT Q0*/ Loading