38 float rms = context->getRMS();
39 u32 timestamp = context->getTimestamp();
69 FL_DBG(
"DropDetector: Drop detected! Impact=" << impact <<
", Bass=" << bassEnergy <<
", Energy flux=" << energyFlux);
109 int endBin =
fl::max(1,
static_cast<int>(
fft.raw().size() / 4));
112 for (
int i = 0; i < endBin; i++) {
113 energy +=
fft.raw()[i];
116 return energy /
static_cast<float>(endBin);
121 int startBin =
static_cast<int>(
fft.raw().size() / 4);
122 int endBin =
static_cast<int>(
fft.raw().size() * 3 / 4);
126 for (
int i = startBin; i < endBin; i++) {
127 energy +=
fft.raw()[i];
131 return (count > 0) ? energy /
static_cast<float>(count) : 0.0f;
136 int startBin =
static_cast<int>(
fft.raw().size() * 3 / 4);
140 for (fl::size i = startBin; i <
fft.raw().size(); i++) {
141 energy +=
fft.raw()[i];
145 return (count > 0) ? energy /
static_cast<float>(count) : 0.0f;
155 float novelty = bassChange * 0.5f + midChange * 0.3f + trebleChange * 0.2f;
158 return fl::min(1.0f, novelty / 2.0f);
196 float impact = energyFlux * 0.4f +
198 spectralNovelty * 0.15f +
199 normalizedRMS * 0.1f;
212 u32 timeSinceLast = timestamp -
mLastDrop.timestamp;
235 const float alpha = 0.9f;
float rms(fl::span< const int16_t > data)
function_list< void(const Drop &)> onDropEvent
void fireCallbacks() FL_NO_EXCEPT override
function_list< void()> onDrop
float mEnergyFluxThreshold
~DropDetector() FL_NO_EXCEPT override
bool mDropDetectedThisFrame
float getBassEnergy(const fft::Bins &fft) const FL_NO_EXCEPT
void update(shared_ptr< Context > context) FL_NO_EXCEPT override
DropDetector() FL_NO_EXCEPT
float calculateSpectralNovelty(float bass, float mid, float treble) const FL_NO_EXCEPT
void updateBaselines(float rms, float bass) FL_NO_EXCEPT
shared_ptr< const fft::Bins > mRetainedFFT
float getMidEnergy(const fft::Bins &fft) const FL_NO_EXCEPT
float calculateBassFlux(float currentBass) const FL_NO_EXCEPT
function_list< void(float impact)> onDropImpact
float getTrebleEnergy(const fft::Bins &fft) const FL_NO_EXCEPT
float calculateEnergyFlux(float currentRMS) const FL_NO_EXCEPT
void reset() FL_NO_EXCEPT override
float calculateDropImpact(float energyFlux, float bassFlux, float spectralNovelty, float rms) const FL_NO_EXCEPT
bool shouldTriggerDrop(float impact, u32 timestamp) const FL_NO_EXCEPT
Centralized logging categories for FastLED hardware interfaces and subsystems.
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NO_EXCEPT
Base definition for an LED controller.
Compile-time rational arithmetic.