From 592e211deb3fb0acf7a7d1678bfacdb5c892359b Mon Sep 17 00:00:00 2001 From: wuggy Date: Mon, 29 Jun 2026 20:01:32 +0100 Subject: [PATCH] AAAAAAAA --- media/libsoundtouch/src/TDStretch.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/media/libsoundtouch/src/TDStretch.cpp b/media/libsoundtouch/src/TDStretch.cpp index e8cd051a32..ef8b8a2d1d 100644 --- a/media/libsoundtouch/src/TDStretch.cpp +++ b/media/libsoundtouch/src/TDStretch.cpp @@ -292,10 +292,10 @@ inline void TDStretch::overlap(SAMPLETYPE *pOutput, const SAMPLETYPE *pInput, ui // The best position is determined as the position where the two overlapped // sample sequences are 'most alike', in terms of the highest cross-correlation // value over the overlapping period -int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos) +int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos) { - int bestOffs; double bestCorr; + int bestOffs; int i; double norm; @@ -306,28 +306,28 @@ int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos) // over the permitted range. bestCorr = calcCrossCorr(refPos, pMidBuffer, norm); bestCorr = (bestCorr + 0.1) * 0.75; + const int seekLen = seekLength; const int nChannels = channels; const SAMPLETYPE *midBuffer = pMidBuffer; #if defined(_OPENMP) - #pragma omp parallel for default(none) shared(refPos, bestCorr, bestOffs, midBuffer) private(i) schedule(static) + #pragma omp parallel for default(none) \ + shared(refPos, bestCorr, bestOffs, midBuffer, seekLen, nChannels) \ + private(i) schedule(static) #endif -for (i = 1; i < seekLen; i ++) + for (i = 1; i < seekLen; i ++) + { double corr; double localNorm; + // Calculates correlation value for the mixing position corresponding to 'i' #if defined(_OPENMP) || defined(ST_SIMD_AVOID_UNALIGNED) - // in parallel OpenMP mode, can't use norm accumulator version as parallel executor won't - // iterate the loop in sequential order - // in SIMD mode, avoid accumulator version to allow avoiding unaligned positions corr = calcCrossCorr(refPos + nChannels * i, midBuffer, localNorm); #else - // In non-parallel version call "calcCrossCorrAccumulate" that is otherwise same - // as "calcCrossCorr", but saves time by reusing & updating previously stored - // "norm" value corr = calcCrossCorrAccumulate(refPos + nChannels * i, midBuffer, norm); #endif + // heuristic rule to slightly favour values close to mid of the range double tmp = (double)(2 * i - seekLen) / (double)seekLen; corr = ((corr + 0.1) * (1.0 - 0.25 * tmp * tmp)); @@ -336,8 +336,6 @@ for (i = 1; i < seekLen; i ++) if (corr > bestCorr) { // For optimal performance, enter critical section only in case that best value found. - // in such case repeat 'if' condition as it's possible that parallel execution may have - // updated the bestCorr value in the mean time #if defined(_OPENMP) #pragma omp critical(soundtouch_bestcorr) #endif @@ -353,7 +351,7 @@ for (i = 1; i < seekLen; i ++) adaptNormalizer(); #endif - // clear cross correlation routine state if necessary (is so e.g. in MMX routines). + // clear cross correlation routine state if necessary clearCrossCorrState(); return bestOffs;