FastLED 3.9.15
Loading...
Searching...
No Matches
exponential_smoother_impl.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/math/math.h"
4
5namespace fl {
6namespace detail {
7
8template <typename T>
10 public:
11 explicit ExponentialSmootherImpl(T tau_seconds, T initial = T(0))
12 : mTau(tau_seconds), mY(initial) {}
13
14 T update(T input, T dt_seconds) {
15 if (mTau <= T(0)) {
16 mY = input; // No smoothing when tau <= 0
17 return mY;
18 }
19 T decay = fl::exp(-(dt_seconds / mTau));
20 mY = input + (mY - input) * decay;
21 return mY;
22 }
23
24 void setTau(T tau_seconds) { mTau = tau_seconds; }
25 T value() const { return mY; }
26 void reset(T initial = T(0)) { mY = initial; }
27
28 private:
30 T mY;
31};
32
33} // namespace detail
34} // namespace fl
ExponentialSmootherImpl(T tau_seconds, T initial=T(0))
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179