38 float rms = context->getRMS();
39 u32 timestamp = context->getTimestamp();
69 FL_DBG(
"DropDetector: Drop detected! Impact=" << impact
70 <<
", Bass=" << bassEnergy
71 <<
", Energy flux=" << energyFlux);
111 int endBin =
fl::max(1,
static_cast<int>(
fft.raw().size() / 4));
114 for (
int i = 0; i < endBin; i++) {
115 energy +=
fft.raw()[i];
118 return energy /
static_cast<float>(endBin);
123 int startBin =
static_cast<int>(
fft.raw().size() / 4);
124 int endBin =
static_cast<int>(
fft.raw().size() * 3 / 4);
128 for (
int i = startBin; i < endBin; i++) {
129 energy +=
fft.raw()[i];
133 return (count > 0) ? energy /
static_cast<float>(count) : 0.0f;
138 int startBin =
static_cast<int>(
fft.raw().size() * 3 / 4);
142 for (fl::size i = startBin; i <
fft.raw().size(); i++) {
143 energy +=
fft.raw()[i];
147 return (count > 0) ? energy /
static_cast<float>(count) : 0.0f;
157 float novelty = bassChange * 0.5f + midChange * 0.3f + trebleChange * 0.2f;
160 return fl::min(1.0f, novelty / 2.0f);
198 float impact = energyFlux * 0.4f +
200 spectralNovelty * 0.15f +
201 normalizedRMS * 0.1f;
214 u32 timeSinceLast = timestamp -
mLastDrop.timestamp;
237 const float alpha = 0.9f;
float rms(fl::span< const int16_t > data)
void update(shared_ptr< Context > context) override
float getTrebleEnergy(const fft::Bins &fft) const
float calculateEnergyFlux(float currentRMS) const
function_list< void(const Drop &)> onDropEvent
bool shouldTriggerDrop(float impact, u32 timestamp) const
function_list< void()> onDrop
float mEnergyFluxThreshold
float calculateBassFlux(float currentBass) const
~DropDetector() FL_NOEXCEPT override
bool mDropDetectedThisFrame
float getBassEnergy(const fft::Bins &fft) const
shared_ptr< const fft::Bins > mRetainedFFT
float calculateDropImpact(float energyFlux, float bassFlux, float spectralNovelty, float rms) const
DropDetector() FL_NOEXCEPT
function_list< void(float impact)> onDropImpact
float getMidEnergy(const fft::Bins &fft) const
void updateBaselines(float rms, float bass)
float calculateSpectralNovelty(float bass, float mid, float treble) const
void fireCallbacks() override
Centralized logging categories for FastLED hardware interfaces and subsystems.
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
constexpr enable_if< is_fixed_point< T >::value, T >::type abs(T x) FL_NOEXCEPT
Base definition for an LED controller.
Compile-time rational arithmetic.