407 {
408 const int n = static_cast<int>(pcm.size());
409
410
413
414 if (minLag >= maxLag || maxLag >= n) return 0.0f;
415
416
417
419
420
421 float acf0 = 0.0f;
422 for (
int i = 0; i < n; i +=
step) {
423 float s = static_cast<float>(pcm[i]);
424 acf0 += s * s;
425 }
426 if (acf0 < 1.0f) return 0.0f;
427
428
429
430 const int lagRange = maxLag - minLag;
431 const int maxProbes = 16;
432 const int lagStep =
fl::max(1, lagRange / maxProbes);
433 float bestPeak = 0.0f;
434 for (int lag = minLag; lag <= maxLag; lag += lagStep) {
435 float sum = 0.0f;
436 for (
int i = 0; i + lag < n; i +=
step) {
437 sum += static_cast<float>(pcm[i]) * static_cast<float>(pcm[i + lag]);
438 }
439 float normalized = sum / acf0;
440 bestPeak =
fl::max(bestPeak, normalized);
441 }
442
443 return 1.0f - bestPeak;
444}
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NOEXCEPT