FastLED 3.10.8
Loading...
Searching...
No Matches

◆ detectTransient() [2/2]

bool fl::audio::detector::Transient::detectTransient ( float flux,
u32 timestamp )
private

Definition at line 113 of file transient.cpp.hpp.

113 {
114 // Check cooldown period
115 u32 timeSinceLastTransient = timestamp - mLastTransientTime;
116 if (timeSinceLastTransient < mMinIntervalMs) {
117 return false;
118 }
119
120 // Calculate adaptive threshold based on recent energy history
121 float adaptiveThreshold = 0.0f;
122 if (!mEnergyHistory.empty()) {
123 float sum = 0.0f;
124 for (size i = 0; i < mEnergyHistory.size(); i++) {
125 sum += mEnergyHistory[i];
126 }
127 float meanEnergy = sum / static_cast<float>(mEnergyHistory.size());
128
129 // Threshold is based on mean energy and configured threshold
130 if (meanEnergy > 1e-6f) {
131 adaptiveThreshold = mThreshold * mSensitivity;
132 }
133 }
134
135 // Check if flux exceeds threshold
136 if (flux <= adaptiveThreshold) {
137 mStrength = 0.0f;
138 return false;
139 }
140
141 // Calculate strength based on how much we exceeded threshold
142 if (adaptiveThreshold > 0.0f) {
143 mStrength = fl::min(1.0f, (flux - adaptiveThreshold) / adaptiveThreshold);
144 } else {
145 mStrength = fl::min(1.0f, flux);
146 }
147
148 return true;
149}
deque< float > mEnergyHistory
Definition transient.h:62
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71

References fl::FL_NO_EXCEPT, mEnergyHistory, fl::min(), mLastTransientTime, mMinIntervalMs, mSensitivity, mStrength, and mThreshold.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: