FastLED 3.10.8
Loading...
Searching...
No Matches

◆ calculateVelocity() [2/2]

u8 fl::audio::detector::Note::calculateVelocity ( float energy,
float confidence ) const
private

Definition at line 206 of file note.cpp.hpp.

206 {
207 // Velocity calculation based on RMS energy and pitch confidence
208 // Higher energy = higher velocity
209 // Higher confidence = more reliable velocity
210
211 // Normalize energy to 0-1 range (typical RMS values: 0.0-1.0)
212 float normalizedEnergy = fl::clamp(energy * mVelocitySensitivity, 0.0f, 1.0f);
213
214 // Weight by confidence (more confident = more accurate velocity)
215 float weightedVelocity = normalizedEnergy * confidence;
216
217 // Convert to MIDI velocity (1-127, 0 reserved for note-off)
218 int velocity = static_cast<int>(weightedVelocity * 126.0f) + 1;
219
220 return static_cast<u8>(fl::clamp(velocity, 1, 127));
221}
unsigned char u8
Definition stdint.h:131
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NO_EXCEPT

References fl::clamp(), fl::FL_NO_EXCEPT, and mVelocitySensitivity.

Referenced by update().

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