test(pitch_shift): tighten purity f0 to 1/196 so revert-of-fadeLen_ fails; add hop guard; clamp fadeLen_ in double before int64 cast

This commit is contained in:
2026-07-28 06:59:04 -04:00
parent 436a685984
commit 3d0406ef64
2 changed files with 21 additions and 11 deletions
+6 -3
View File
@@ -186,9 +186,12 @@ void PitchShifter::splice(std::int64_t nominalJump) {
fadeLen_ = fadeFrames_;
if (ratio_ > 1.0) {
const double headroom = static_cast<double>(dLow_) - (ratio_ - 1.0) - 2.0;
const std::int64_t safe =
headroom > 0.0 ? static_cast<std::int64_t>(headroom / (ratio_ - 1.0)) : 1;
fadeLen_ = std::max<std::int64_t>(1, std::min(fadeFrames_, safe));
// Clamp in double before the int64 cast to avoid UB at pathological near-unity ratios
// at very high sample rates (where headroom/(ratio_-1.0) could overflow int64).
const double safeDbl = headroom > 0.0
? std::min(headroom / (ratio_ - 1.0), static_cast<double>(fadeFrames_))
: 1.0;
fadeLen_ = std::max<std::int64_t>(1, static_cast<std::int64_t>(safeDbl));
}
fading_ = true;
fadePos_ = 0;