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

◆ detectBeat()

bool detectBeat ( float energy)

Definition at line 117 of file advanced.h.

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

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: