FastLED 3.9.15
Loading...
Searching...
No Matches

◆ update()

template<typename T = float>
T fl::detail::SpectralVarianceImpl< T >::update ( fl::span< const T > bins)
inline

Feed a new frame of multi-channel data.

Returns mean relative deviation. First call initializes internal state and returns 0.

Definition at line 36 of file spectral_variance_impl.h.

36 {
37 const int n = static_cast<int>(bins.size());
38 if (n == 0) return T(0);
39
40 // Initialize on first call or if channel count changes
41 if (mSmoothed.size() != static_cast<fl::size>(n)) {
42 mSmoothed.resize(n);
43 for (int i = 0; i < n; ++i) {
44 mSmoothed[i] = bins[i];
45 }
46 mVariance = T(0);
47 return T(0);
48 }
49
50 T sumRelChange = T(0);
51 int activeCount = 0;
52
53 for (int i = 0; i < n; ++i) {
56
57 // Only count channels with meaningful energy
58 if (smoothed > mFloor) {
59 T diff = bins[i] - smoothed;
60 T absDiff = (diff >= T(0)) ? diff : -diff;
63 }
64
65 // Update EMA: smoothed = alpha * current + (1-alpha) * smoothed
66 mSmoothed[i] = mAlpha * bins[i] + (T(1) - mAlpha) * smoothed;
67 }
68
69 mVariance = (activeCount >= 2)
70 ? sumRelChange / static_cast<T>(activeCount)
71 : T(0);
72 return mVariance;
73 }
fl::size size() const
Get the number of channels being tracked.
Multi-channel EMA with per-bin relative deviation measurement.

References mAlpha, mFloor, mSmoothed, mVariance, and fl::span< T, Extent >::size().

+ Here is the call graph for this function: