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

◆ calculatePitchBend() [2/2]

float fl::audio::detector::Note::calculatePitchBend ( float hz,
u8 note ) const
private

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

188 {
189 if (note == NO_NOTE || hz <= 0.0f) {
190 return 0.0f;
191 }
192
193 float noteFrequency = midiNoteToFrequency(note);
194 if (noteFrequency <= 0.0f) {
195 return 0.0f;
196 }
197
198 // Calculate cents deviation from note center
199 // Cents = 1200 × log₂(f / f_note)
200 float cents = 1200.0f * (fl::logf(hz / noteFrequency) / fl::logf(2.0f));
201
202 // Clamp to ±50 cents (typical range within a single note)
203 return fl::clamp(cents, -50.0f, 50.0f);
204}
float midiNoteToFrequency(u8 note) const FL_NO_EXCEPT
Definition note.cpp.hpp:178
static constexpr u8 NO_NOTE
Definition note.h:110
float logf(float value) FL_NO_EXCEPT
Definition math.h:426
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, fl::logf(), midiNoteToFrequency(), and NO_NOTE.

Referenced by update().

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