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

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
 
u8 calculateVelocity (float energy, float confidence) const
 
u8 calculateVelocity (float energy, float confidence) const
 
u8 frequencyToMidiNote (float hz) const
 
float midiNoteToFrequency (u8 note) const
 
bool shouldTriggerNoteChange (u8 newNote, u8 currentNote) const
 
bool shouldTriggerNoteChange (u8 newNote, u8 currentNote) const
 
bool shouldTriggerNoteOff (float confidence, bool voiced) const
 
bool shouldTriggerNoteOff (float confidence, bool voiced) const
 
bool shouldTriggerNoteOn (float confidence, float pitch) const
 
bool shouldTriggerNoteOn (float confidence, float pitch) const
 

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< PitchmPitchDetector
 
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: