From fae7050113dff12db6b9800f876d27496e3d4e85 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 25 Sep 2022 17:37:25 +0200 Subject: [PATCH] Add helper to compensate smoother for oversampling --- src/param/smoothing.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/param/smoothing.rs b/src/param/smoothing.rs index 40451a8c..c26acb3f 100644 --- a/src/param/smoothing.rs +++ b/src/param/smoothing.rs @@ -64,6 +64,18 @@ pub struct SmootherIter<'a, T: Smoothable> { } impl SmoothingStyle { + /// Utility function to modify the duration to compensate for an oversampling factor. When using + /// 4x oversampling, the duration needs to be four times as long to compensate for the four + /// times higher effective sample rate. + pub fn for_oversampling_factor(self, factor: f32) -> Self { + match self { + SmoothingStyle::None => SmoothingStyle::None, + SmoothingStyle::Linear(time) => SmoothingStyle::Linear(time * factor), + SmoothingStyle::Logarithmic(time) => SmoothingStyle::Logarithmic(time * factor), + SmoothingStyle::Exponential(time) => SmoothingStyle::Exponential(time * factor), + } + } + /// Compute the number of steps to reach the target value based on the sample rate and this /// smoothing style's duration. #[inline]