FastLED 3.9.15
Loading...
Searching...
No Matches

◆ detectBeat()

bool detectBeat ( float energy)

Definition at line 115 of file advanced.h.

115 {
118
119 // Calculate average
120 beatAverage = 0;
121 for (int i = 0; i < 20; i++) {
123 }
124 beatAverage /= 20.0f;
125
126 // Calculate variance
127 beatVariance = 0;
128 for (int i = 0; i < 20; i++) {
129 float diff = beatHistory[i] - beatAverage;
130 beatVariance += diff * diff;
131 }
132 beatVariance /= 20.0f;
133
134 // Detect beat
135 float threshold = beatAverage + (beatSensitivity.value() * sqrt(beatVariance));
136 uint32_t currentTime = millis();
137
138 if (energy > threshold && (currentTime - lastBeatTime) > 80) {
139 lastBeatTime = currentTime;
140 return true;
141 }
142 return false;
143}
UISlider beatSensitivity("Beat Sensitivity", 1.5f, 0.5f, 3.0f, 0.1f)
uint32_t lastBeatTime
Definition advanced.h:87
float beatAverage
Definition advanced.h:85
float beatVariance
Definition advanced.h:86
int beatHistoryIndex
Definition advanced.h:84
float beatHistory[20]
Definition advanced.h:83

References beatAverage, beatHistory, beatHistoryIndex, beatSensitivity(), beatVariance, and lastBeatTime.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: