FastLED 3.9.15
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) override;
26 void fireCallbacks() override;
27 bool needsFFT() const override { return true; }
28 bool needsFFTHistory() const override { return false; }
29 const char* getName() const override { return "Percussion"; }
30 void reset() 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 { return mKickDetected; }
41 bool isSnare() const { return mSnareDetected; }
42 bool isHiHat() const { return mHiHatDetected; }
43 bool isTom() const { return mTomDetected; }
44
45 // Confidence (0.0 - 1.0)
46 float getKickConfidence() const { return mKickConfidence; }
47 float getSnareConfidence() const { return mSnareConfidence; }
48 float getHiHatConfidence() const { return mHiHatConfidence; }
49 float getTomConfidence() const { return mTomConfidence; }
50
51 // Feature inspection (for calibration / testing)
52 float getBassToTotalRatio() const { return mBassToTotal; }
53 float getTrebleToTotalRatio() const { return mTrebleToTotal; }
54 float getClickRatio() const { return mClickRatio; }
55 float getTrebleFlatness() const { return mTrebleFlatness; }
56 float getMidToTrebleRatio() const { return mMidToTreble; }
57 float getOnsetSharpness() const { return mOnsetSharpness; }
58 float getSubBassProxy() const { return mSubBassProxy; }
60
61 // Configuration
62 void setKickThreshold(float threshold) { mKickThreshold = threshold; }
63 void setSnareThreshold(float threshold) { mSnareThreshold = threshold; }
64 void setHiHatThreshold(float threshold) { mHiHatThreshold = threshold; }
65 void setTomThreshold(float threshold) { 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
113 void computeFeatures(const fft::Bins& fft);
114 void computeConfidences();
116};
117
118} // namespace detector
119} // namespace audio
120} // namespace fl
static constexpr u32 SNARE_COOLDOWN_MS
Definition percussion.h:108
shared_ptr< const fft::Bins > mRetainedFFT
Definition percussion.h:105
AttackDecayFilter< float > mTotalEnvelope
Definition percussion.h:97
function_list< void(PercussionType type)> onPercussionHit
Definition percussion.h:33
float getZeroCrossingFactor() const
Definition percussion.h:59
function_list< void()> onKick
Definition percussion.h:34
static constexpr u32 KICK_COOLDOWN_MS
Definition percussion.h:107
void setSnareThreshold(float threshold)
Definition percussion.h:63
function_list< void()> onSnare
Definition percussion.h:35
static constexpr u32 HIHAT_COOLDOWN_MS
Definition percussion.h:109
float getTrebleToTotalRatio() const
Definition percussion.h:53
function_list< void()> onTom
Definition percussion.h:37
void setKickThreshold(float threshold)
Definition percussion.h:62
void computeFeatures(const fft::Bins &fft)
~Percussion() FL_NOEXCEPT override
void setHiHatThreshold(float threshold)
Definition percussion.h:64
void update(shared_ptr< Context > context) override
static constexpr u32 TOM_COOLDOWN_MS
Definition percussion.h:110
bool needsFFT() const override
Definition percussion.h:27
function_list< void()> onHiHat
Definition percussion.h:36
bool needsFFTHistory() const override
Definition percussion.h:28
const char * getName() const override
Definition percussion.h:29
void setTomThreshold(float threshold)
Definition percussion.h:65
unsigned char u8
Definition stdint.h:131
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT