FastLED 3.9.15
Loading...
Searching...
No Matches

◆ update()

void fl::audio::detector::MoodAnalyzer::update ( shared_ptr< Context > context)
overridevirtual

Implements fl::audio::Detector.

Definition at line 30 of file mood_analyzer.cpp.hpp.

30 {
31 mRetainedFFT = context->getFFT(32); // Higher resolution for mood analysis
32 const fft::Bins& fft = *mRetainedFFT;
33 const fft::Bins* prevFFT = context->getHistoricalFFT(1);
34
35 // Extract audio features
39 mZeroCrossingRate = context->getZCF();
40 mRMSEnergy = context->getRMS();
41
42 // Calculate mood dimensions
45
46 // Add to history for temporal averaging
47 if (static_cast<int>(mValenceHistory.size()) < mAveragingFrames) {
48 mValenceHistory.push_back(valence);
49 mArousalHistory.push_back(arousal);
50 mHistoryIndex = static_cast<int>(mValenceHistory.size()) % mAveragingFrames;
51 } else {
55 }
56
57 // Average over history for stability
58 float avgValence = 0.0f;
59 float avgArousal = 0.0f;
60 for (size_t i = 0; i < mValenceHistory.size(); i++) {
61 avgValence += mValenceHistory[i];
62 avgArousal += mArousalHistory[i];
63 }
64 avgValence /= mValenceHistory.size();
65 avgArousal /= mArousalHistory.size();
66
67 // Update current mood
69 mCurrentMood.valence = avgValence;
70 mCurrentMood.arousal = avgArousal;
71 mCurrentMood.confidence = calculateConfidence(avgValence, avgArousal);
72 mCurrentMood.timestamp = context->getTimestamp();
73
74 // Update duration if mood is stable
75 if (mPreviousMood.getCategory() == mCurrentMood.getCategory()) {
76 mCurrentMood.duration = mPreviousMood.duration +
77 (mCurrentMood.timestamp - mPreviousMood.timestamp);
78 } else {
79 mCurrentMood.duration = 0;
80 }
81
82 // Check for mood changes (store result for fireCallbacks)
84}
AudioAnalyzeFFT1024 fft
float calculateSpectralCentroid(const fft::Bins &fft)
fl::vector< float > mArousalHistory
bool shouldChangeMood(const Mood &newMood)
fl::vector< float > mValenceHistory
shared_ptr< const fft::Bins > mRetainedFFT
float calculateSpectralFlux(const fft::Bins &fft, const fft::Bins *prevFFT)
float calculateSpectralRolloff(const fft::Bins &fft, float threshold=0.85f)
float calculateArousal(float rms, float zcr, float flux)
float calculateValence(float centroid, float rolloff, float flux)
float calculateConfidence(float valence, float arousal)

References MoodAnalyzer(), calculateArousal(), calculateConfidence(), calculateSpectralCentroid(), calculateSpectralFlux(), calculateSpectralRolloff(), calculateValence(), mArousalHistory, mAveragingFrames, mCurrentMood, mHistoryIndex, mMoodChanged, mPreviousMood, mRetainedFFT, mRMSEnergy, mSpectralCentroid, mSpectralFlux, mSpectralRolloff, mValenceHistory, mZeroCrossingRate, shouldChangeMood(), and update().

Referenced by ~MoodAnalyzer(), and update().

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