This commit is contained in:
wuggy 2026-06-29 20:01:32 +01:00
commit 592e211deb

View file

@ -294,8 +294,8 @@ inline void TDStretch::overlap(SAMPLETYPE *pOutput, const SAMPLETYPE *pInput, ui
// value over the overlapping period // value over the overlapping period
int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos) int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos)
{ {
int bestOffs;
double bestCorr; double bestCorr;
int bestOffs;
int i; int i;
double norm; double norm;
@ -306,28 +306,28 @@ int TDStretch::seekBestOverlapPositionFull(const SAMPLETYPE *refPos)
// over the permitted range. // over the permitted range.
bestCorr = calcCrossCorr(refPos, pMidBuffer, norm); bestCorr = calcCrossCorr(refPos, pMidBuffer, norm);
bestCorr = (bestCorr + 0.1) * 0.75; bestCorr = (bestCorr + 0.1) * 0.75;
const int seekLen = seekLength; const int seekLen = seekLength;
const int nChannels = channels; const int nChannels = channels;
const SAMPLETYPE *midBuffer = pMidBuffer; const SAMPLETYPE *midBuffer = pMidBuffer;
#if defined(_OPENMP) #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 #endif
for (i = 1; i < seekLen; i ++) for (i = 1; i < seekLen; i ++)
{
double corr; double corr;
double localNorm; double localNorm;
// Calculates correlation value for the mixing position corresponding to 'i' // Calculates correlation value for the mixing position corresponding to 'i'
#if defined(_OPENMP) || defined(ST_SIMD_AVOID_UNALIGNED) #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); corr = calcCrossCorr(refPos + nChannels * i, midBuffer, localNorm);
#else #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); corr = calcCrossCorrAccumulate(refPos + nChannels * i, midBuffer, norm);
#endif #endif
// heuristic rule to slightly favour values close to mid of the range // heuristic rule to slightly favour values close to mid of the range
double tmp = (double)(2 * i - seekLen) / (double)seekLen; double tmp = (double)(2 * i - seekLen) / (double)seekLen;
corr = ((corr + 0.1) * (1.0 - 0.25 * tmp * tmp)); corr = ((corr + 0.1) * (1.0 - 0.25 * tmp * tmp));
@ -336,8 +336,6 @@ for (i = 1; i < seekLen; i ++)
if (corr > bestCorr) if (corr > bestCorr)
{ {
// For optimal performance, enter critical section only in case that best value found. // 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) #if defined(_OPENMP)
#pragma omp critical(soundtouch_bestcorr) #pragma omp critical(soundtouch_bestcorr)
#endif #endif
@ -353,7 +351,7 @@ for (i = 1; i < seekLen; i ++)
adaptNormalizer(); adaptNormalizer();
#endif #endif
// clear cross correlation routine state if necessary (is so e.g. in MMX routines). // clear cross correlation routine state if necessary
clearCrossCorrState(); clearCrossCorrState();
return bestOffs; return bestOffs;