FastLED 3.9.15
Loading...
Searching...
No Matches
attack_decay_filter_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 AttackDecayFilterImpl(T attack_tau, T decay_tau, T initial = T(0))
12 : mAttackTau(attack_tau), mDecayTau(decay_tau), mY(initial) {}
13
14 T update(T input, T dt_seconds) {
15 T abs_input = (input < T(0)) ? -input : input;
16 T abs_y = (mY < T(0)) ? -mY : mY;
17 T tau = (abs_input > abs_y) ? mAttackTau : mDecayTau;
18 if (tau <= T(0)) {
19 mY = input; // No smoothing when tau <= 0
20 return mY;
21 }
22 T decay = fl::exp(-(dt_seconds / tau));
23 mY = input + (mY - input) * decay;
24 return mY;
25 }
26
27 void setAttackTau(T tau_seconds) { mAttackTau = tau_seconds; }
28 void setDecayTau(T tau_seconds) { mDecayTau = tau_seconds; }
29 T value() const { return mY; }
30 void reset(T initial = T(0)) { mY = initial; }
31
32 private:
35 T mY;
36};
37
38} // namespace detail
39} // namespace fl
AttackDecayFilterImpl(T attack_tau, T decay_tau, 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