FastLED 3.9.15
Loading...
Searching...
No Matches
transient_detector.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/vector.h"
4#include "fl/stl/noexcept.h"
5
6namespace fl {
7namespace audio {
8namespace detector {
9
10class Transient {
11public:
14
15 void update(shared_ptr<Context> context);
16 void reset();
17
18 // Callback types
19 using TransientCallback = void(*)();
20 using TransientStrengthCallback = void(*)(float strength);
21
22 // Callback functions
23 TransientCallback onTransient = nullptr; // Simple transient detection
24 TransientStrengthCallback onTransientWithStrength = nullptr; // With strength parameter
25 TransientStrengthCallback onAttack = nullptr; // Attack phase of transient
26
27 // Configurable parameters
28 void setThreshold(float threshold) { mThreshold = threshold; }
30
31 // Getters
32 bool isTransientDetected() const { return mTransientDetected; }
33 float getStrength() const { return mStrength; }
34 float getAttackTime() const { return mAttackTime; }
35
36private:
37 // Constants
38 static constexpr size_t ENERGY_HISTORY_SIZE = 32;
39
40 // Detection state
42 float mStrength;
43 float mThreshold;
44 float mSensitivity;
47
48 // Energy tracking
49 float mPreviousEnergy;
50 float mCurrentEnergy;
53
54 // Attack time estimation
55 float mAttackTime;
56
57 // Internal processing methods
59 float calculateEnergyFlux(float currentEnergy);
60 bool detectTransient(float flux, u32 timestamp);
61 void updateAttackTime(float flux);
62};
63
64} // namespace detector
65} // namespace audio
66} // namespace fl
fl::UISlider sensitivity("Sensitivity", 1.5f, 0.3f, 4.0f, 0.1f)
float calculateEnergyFlux(float currentEnergy)
function_list< void()> onTransient
Definition transient.h:33
function_list< void(float strength)> onTransientWithStrength
Definition transient.h:34
vector< float > mPreviousHighFreq
Definition transient.h:61
bool detectTransient(float flux, u32 timestamp)
float calculateHighFreqEnergy(const fft::Bins &fft)
void update(shared_ptr< Context > context) override
void(*)(float strength) TransientStrengthCallback
void updateAttackTime(float flux)
void setThreshold(float threshold)
Definition transient.h:43
function_list< void(float strength)> onAttack
Definition transient.h:35
static constexpr size ENERGY_HISTORY_SIZE
Definition transient.h:63
deque< float > mEnergyHistory
Definition transient.h:62
void setSensitivity(float sensitivity)
Transient - Detects sharp attack transients in audio.
Definition transient.h:21
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT