MCPcopy Create free account
hub / github.com/FastLED/FastLED / update

Method update

src/fl/audio/detector/chord.cpp.hpp:61–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void ChordDetector::update(shared_ptr<Context> context) {
62 mRetainedFFT = context->getFFT(32); // Higher resolution for pitch detection
63 const fft::Bins& fft = *mRetainedFFT;
64 u32 timestamp = context->getTimestamp();
65
66 // Calculate chroma features
67 calculateChroma(fft);
68
69 // Detect current chord
70 Chord detected = detectChord(mChroma, timestamp);
71
72 // Check if chord changed
73 if (detected.isValid() && detected.confidence >= mConfidenceThreshold) {
74 if (!mCurrentChord.isValid() || !isSimilarChord(detected, mCurrentChord)) {
75 // New chord detected
76 if (mCurrentChord.isValid()) {
77 mFireChordEnd = true;
78 }
79
80 mPreviousChord = mCurrentChord;
81 mCurrentChord = detected;
82 mChordStartTime = timestamp;
83
84 mFireChordChange = true;
85
86 FL_DBG("Chord detected: " << mCurrentChord.getRootName()
87 << mCurrentChord.getTypeName()
88 << " (conf: " << mCurrentChord.confidence << ")");
89 } else {
90 // Same chord, update confidence
91 mCurrentChord.confidence = detected.confidence;
92 mCurrentChord.timestamp = timestamp;
93 }
94
95 // Set flag for onChord callback every frame when chord is active
96 mFireChord = true;
97 } else {
98 // No valid chord or low confidence
99 if (mCurrentChord.isValid()) {
100 u32 duration = timestamp - mChordStartTime;
101 if (duration >= mMinChordDuration) {
102 mChordEndTime = timestamp;
103 mFireChordEnd = true;
104 }
105 mCurrentChord = Chord(); // Reset to invalid
106 }
107 }
108
109 // Save chroma for next frame
110 for (int i = 0; i < 12; i++) {
111 mPrevChroma[i] = mChroma[i];
112 }
113}
114
115void ChordDetector::fireCallbacks() {
116 if (mFireChordEnd) {

Callers

nothing calls this directly

Calls 6

getFFTMethod · 0.80
getTypeNameMethod · 0.80
ChordClass · 0.70
getTimestampMethod · 0.45
isValidMethod · 0.45
getRootNameMethod · 0.45

Tested by

no test coverage detected