FastLED 3.10.8
Loading...
Searching...
No Matches
fl::audio::detector::Note Class Reference

Detailed Description

Note - Musical note detection with MIDI output.

Converts continuous pitch (from Pitch) to discrete musical notes using 12-tone equal temperament (12-TET). Provides note-on/note-off events with velocity information based on attack strength.

Key Features:

  • Converts Hz to MIDI note numbers (A4 = 440 Hz = MIDI 69)
  • Note-on/note-off events with hysteresis for stability
  • Velocity calculation based on attack strength
  • Configurable note-on/note-off thresholds
  • Integration with Pitch for fundamental frequency tracking
  • Support for polyphonic detection (future enhancement)

Performance:

  • Depends on Pitch (no FFT required)
  • Update time: ~0.05-0.1ms per frame (lightweight decision logic)
  • Memory: ~100 bytes

Definition at line 32 of file note.h.

#include <note.h>

+ Inheritance diagram for fl::audio::detector::Note:
+ Collaboration diagram for fl::audio::detector::Note:

Public Types

using NoteStartCallback = void(*)(u8 note, u8 velocity)
 
using NoteVelocityCallback = void(*)(u8 note)
 

Public Member Functions

 Note () FL_NO_EXCEPT
 
 Note () FL_NO_EXCEPT
 
 Note (shared_ptr< Pitch > pitchDetector)
 
 Note (shared_ptr< Pitch > pitchDetector) FL_NO_EXCEPT
 
 ~Note () FL_NO_EXCEPT
 
 ~Note () FL_NO_EXCEPT override
 
void fireCallbacks () FL_NO_EXCEPT override
 
u8 frequencyToMidiNote (float hz) const
 
u8 getCurrentNote () const
 
u8 getCurrentNote () const FL_NO_EXCEPT
 
float getCurrentPitch () const
 
float getCurrentPitch () const FL_NO_EXCEPT
 
u8 getLastVelocity () const
 
u8 getLastVelocity () const FL_NO_EXCEPT
 
const char * getName () const FL_NO_EXCEPT override
 
float getPitchBend () const
 
float getPitchBend () const FL_NO_EXCEPT
 
shared_ptr< Pitch > getPitchDetector () const FL_NO_EXCEPT
 
bool isNoteActive () const FL_NO_EXCEPT
 
float midiNoteToFrequency (u8 note) const
 
bool needsFFT () const FL_NO_EXCEPT override
 
void reset ()
 
void reset () FL_NO_EXCEPT override
 
void setMinNoteDuration (u32 ms)
 
void setMinNoteDuration (u32 ms) FL_NO_EXCEPT
 
void setNoteChangeThreshold (int semitones)
 
void setNoteChangeThreshold (u8 semitones) FL_NO_EXCEPT
 
void setNoteOffThreshold (float confidenceThreshold) FL_NO_EXCEPT
 
void setNoteOffThreshold (float threshold)
 
void setNoteOnThreshold (float confidenceThreshold) FL_NO_EXCEPT
 
void setNoteOnThreshold (float threshold)
 
void setPitchDetector (shared_ptr< Pitch > pitchDetector) FL_NO_EXCEPT
 
void setVelocitySensitivity (float sensitivity)
 
void setVelocitySensitivity (float sensitivity) FL_NO_EXCEPT
 
void update (shared_ptr< Context > context)
 
void update (shared_ptr< Context > context) FL_NO_EXCEPT override
 
- Public Member Functions inherited from fl::audio::Detector
virtual ~Detector () FL_NO_EXCEPT=default
 
virtual bool needsFFTHistory () const FL_NO_EXCEPT
 
virtual void setSampleRate (int) FL_NO_EXCEPT
 

Public Attributes

function_list< void(u8 note, u8 velocity)> onNoteChange
 
NoteStartCallback onNoteChange = nullptr
 
function_list< void(u8 note)> onNoteOff
 
NoteVelocityCallback onNoteOff = nullptr
 
function_list< void(u8 note, u8 velocity)> onNoteOn
 
NoteStartCallback onNoteOn = nullptr
 

Private Member Functions

float calculatePitchBend (float hz, u8 note) const
 
float calculatePitchBend (float hz, u8 note) const FL_NO_EXCEPT
 
u8 calculateVelocity (float energy, float confidence) const
 
u8 calculateVelocity (float energy, float confidence) const FL_NO_EXCEPT
 
u8 frequencyToMidiNote (float hz) const FL_NO_EXCEPT
 
float midiNoteToFrequency (u8 note) const FL_NO_EXCEPT
 
bool shouldTriggerNoteChange (u8 newNote, u8 currentNote) const
 
bool shouldTriggerNoteChange (u8 newNote, u8 currentNote) const FL_NO_EXCEPT
 
bool shouldTriggerNoteOff (float confidence, bool voiced) const
 
bool shouldTriggerNoteOff (float confidence, bool voiced) const FL_NO_EXCEPT
 
bool shouldTriggerNoteOn (float confidence, float pitch) const
 
bool shouldTriggerNoteOn (float confidence, float pitch) const FL_NO_EXCEPT
 

Private Attributes

u8 mCurrentNote
 
float mCurrentPitch
 
bool mFireNoteChange = false
 
bool mFireNoteOff = false
 
bool mFireNoteOn = false
 
u32 mLastUpdateTime
 
u8 mLastVelocity
 
u32 mMinNoteDuration
 
bool mNoteActive
 
u8 mNoteChangeThreshold
 
int mNoteChangeThreshold
 
float mNoteOffThreshold
 
float mNoteOnEnergy
 
float mNoteOnThreshold
 
u32 mNoteOnTime
 
bool mOwnsPitchDetector
 
u8 mPendingOffNote = 0
 
u8 mPendingOnNote = 0
 
u8 mPendingOnVelocity = 0
 
float mPitchBend
 
shared_ptr< Pitch > mPitchDetector
 
float mVelocitySensitivity
 

Static Private Attributes

static constexpr float A4_FREQUENCY = 440.0f
 
static constexpr u8 A4_MIDI_NOTE = 69
 
static constexpr u8 NO_NOTE = 255
 

The documentation for this class was generated from the following files: