FastLED 3.9.15
Loading...
Searching...
No Matches
gaussian_filter_impl.h
Go to the documentation of this file.
1#pragma once
2
4#include "fl/stl/span.h"
5#include "fl/stl/noexcept.h"
6
7namespace fl {
8namespace detail {
9
10template <typename T, fl::size N = 0>
12 public:
14 explicit GaussianFilterImpl(fl::size capacity)
15 : mBuf(capacity), mLastValue(T(0)) {}
16
17 T update(T input) {
18 mBuf.push_back(input);
19 return recompute();
20 }
21
23 if (values.size() == 0) return mLastValue;
24 for (fl::size i = 0; i < values.size(); ++i) {
25 mBuf.push_back(values[i]);
26 }
27 return recompute();
28 }
29
30 T value() const { return mLastValue; }
31 void reset() { mBuf.clear(); mLastValue = T(0); }
32 bool full() const { return mBuf.full(); }
33 fl::size size() const { return mBuf.size(); }
34 fl::size capacity() const { return mBuf.capacity(); }
35
36 void resize(fl::size new_capacity) {
37 mBuf = circular_buffer<T, N>(new_capacity);
38 mLastValue = T(0);
39 }
40
41 private:
43 fl::size n = mBuf.size();
44 if (n == 0) { mLastValue = T(0); return mLastValue; }
45
46 T weighted_sum = T(0);
47 T weight_total = T(0);
48 fl::size binom = 1;
49 for (fl::size i = 0; i < n; ++i) {
50 T w = T(static_cast<float>(binom));
51 weighted_sum = weighted_sum + mBuf[i] * w;
52 weight_total = weight_total + w;
53 if (i + 1 < n) {
54 binom = binom * (n - 1 - i) / (i + 1);
55 }
56 }
57 mLastValue = weighted_sum / weight_total;
58 return mLastValue;
59 }
60
63};
64
65} // namespace detail
66} // namespace fl
T update(fl::span< const T > values)
void resize(fl::size new_capacity)
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT