FastLED 3.10.8
Loading...
Searching...
No Matches
percussion.h
Go to the documentation of this file.
1#pragma once
2
5#include "fl/stl/int.h"
6#include "fl/stl/function.h"
7#include "fl/stl/noexcept.h"
8
9namespace fl {
10namespace audio {
11namespace detector {
12
19
20class Percussion : public Detector {
21public:
24
25 void update(shared_ptr<Context> context) FL_NO_EXCEPT override;
26 void fireCallbacks() FL_NO_EXCEPT override;
27 bool needsFFT() const FL_NO_EXCEPT override { return true; }
28 bool needsFFTHistory() const FL_NO_EXCEPT override { return false; }
29 const char* getName() const FL_NO_EXCEPT override { return "Percussion"; }
30 void reset() FL_NO_EXCEPT override;
31
32 // Callbacks (multiple listeners supported)
33 function_list<void(PercussionType type)> onPercussionHit;
34 function_list<void()> onKick;
35 function_list<void()> onSnare;
36 function_list<void()> onHiHat;
37 function_list<void()> onTom;
38
39 // State access (polling getters)
40 bool isKick() const FL_NO_EXCEPT { return mKickDetected; }
41 bool isSnare() const FL_NO_EXCEPT { return mSnareDetected; }
42 bool isHiHat() const FL_NO_EXCEPT { return mHiHatDetected; }
43 bool isTom() const FL_NO_EXCEPT { return mTomDetected; }
44
45 // Confidence (0.0 - 1.0)
50
51 // Feature inspection (for calibration / testing)
54 float getClickRatio() const FL_NO_EXCEPT { return mClickRatio; }
58 float getSubBassProxy() const FL_NO_EXCEPT { return mSubBassProxy; }
60
61 // Configuration
62 void setKickThreshold(float threshold) FL_NO_EXCEPT { mKickThreshold = threshold; }
63 void setSnareThreshold(float threshold) FL_NO_EXCEPT { mSnareThreshold = threshold; }
64 void setHiHatThreshold(float threshold) FL_NO_EXCEPT { mHiHatThreshold = threshold; }
65 void setTomThreshold(float threshold) FL_NO_EXCEPT { mTomThreshold = threshold; }
66
67private:
68 // Per-frame detection state
73
74 // Confidence scores (0.0 - 1.0)
79
80 // Spectral features (computed per frame)
89
90 // Thresholds
95
96 // Envelope followers for onset detection
98
99 // Cooldown timestamps
104
106
107 static constexpr u32 KICK_COOLDOWN_MS = 100;
108 static constexpr u32 SNARE_COOLDOWN_MS = 80;
109 static constexpr u32 HIHAT_COOLDOWN_MS = 50;
110 static constexpr u32 TOM_COOLDOWN_MS = 100;
111
112 // Feature computation
116};
117
118} // namespace detector
119} // namespace audio
120} // namespace fl
void update(shared_ptr< Context > context) FL_NO_EXCEPT override
static constexpr u32 SNARE_COOLDOWN_MS
Definition percussion.h:108
void setKickThreshold(float threshold) FL_NO_EXCEPT
Definition percussion.h:62
shared_ptr< const fft::Bins > mRetainedFFT
Definition percussion.h:105
AttackDecayFilter< float > mTotalEnvelope
Definition percussion.h:97
float getKickConfidence() const FL_NO_EXCEPT
Definition percussion.h:46
function_list< void(PercussionType type)> onPercussionHit
Definition percussion.h:33
void setHiHatThreshold(float threshold) FL_NO_EXCEPT
Definition percussion.h:64
bool isTom() const FL_NO_EXCEPT
Definition percussion.h:43
function_list< void()> onKick
Definition percussion.h:34
float getTomConfidence() const FL_NO_EXCEPT
Definition percussion.h:49
static constexpr u32 KICK_COOLDOWN_MS
Definition percussion.h:107
float getSnareConfidence() const FL_NO_EXCEPT
Definition percussion.h:47
const char * getName() const FL_NO_EXCEPT override
Definition percussion.h:29
function_list< void()> onSnare
Definition percussion.h:35
static constexpr u32 HIHAT_COOLDOWN_MS
Definition percussion.h:109
bool needsFFT() const FL_NO_EXCEPT override
Definition percussion.h:27
void computeFeatures(const fft::Bins &fft) FL_NO_EXCEPT
float getSubBassProxy() const FL_NO_EXCEPT
Definition percussion.h:58
bool needsFFTHistory() const FL_NO_EXCEPT override
Definition percussion.h:28
void applyCrossBandRejection() FL_NO_EXCEPT
void setTomThreshold(float threshold) FL_NO_EXCEPT
Definition percussion.h:65
void fireCallbacks() FL_NO_EXCEPT override
void computeConfidences() FL_NO_EXCEPT
~Percussion() FL_NO_EXCEPT override
float getMidToTrebleRatio() const FL_NO_EXCEPT
Definition percussion.h:56
bool isHiHat() const FL_NO_EXCEPT
Definition percussion.h:42
float getZeroCrossingFactor() const FL_NO_EXCEPT
Definition percussion.h:59
float getClickRatio() const FL_NO_EXCEPT
Definition percussion.h:54
void setSnareThreshold(float threshold) FL_NO_EXCEPT
Definition percussion.h:63
float getTrebleFlatness() const FL_NO_EXCEPT
Definition percussion.h:55
bool isSnare() const FL_NO_EXCEPT
Definition percussion.h:41
function_list< void()> onTom
Definition percussion.h:37
float getHiHatConfidence() const FL_NO_EXCEPT
Definition percussion.h:48
float getBassToTotalRatio() const FL_NO_EXCEPT
Definition percussion.h:52
float getTrebleToTotalRatio() const FL_NO_EXCEPT
Definition percussion.h:53
static constexpr u32 TOM_COOLDOWN_MS
Definition percussion.h:110
bool isKick() const FL_NO_EXCEPT
Definition percussion.h:40
float getOnsetSharpness() const FL_NO_EXCEPT
Definition percussion.h:57
function_list< void()> onHiHat
Definition percussion.h:36
void reset() FL_NO_EXCEPT override
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179