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

◆ calculateValence()

float fl::audio::detector::MoodAnalyzer::calculateValence ( float centroid,
float rolloff,
float flux )
private

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

162 {
163 // Valence estimation based on spectral characteristics
164 // Higher frequencies and brighter timbre = more positive
165 // Lower frequencies and darker timbre = more negative
166
167 // Normalize centroid to 0-1 range (assuming 32 bins)
168 float normalizedCentroid = centroid / 32.0f;
169
170 // Brightness score (higher = more positive)
171 float brightness = normalizedCentroid * rolloff;
172
173 // Stability score (lower flux = more positive/calm, higher = more negative/chaotic)
174 float stability = 1.0f - fl::min(1.0f, flux / 10.0f);
175
176 // Combine into valence (-1 to 1)
177 float valence = (brightness * 0.6f + stability * 0.4f) * 2.0f - 1.0f;
178
179 // Clamp to valid range
180 return fl::max(-1.0f, fl::min(1.0f, valence));
181}
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NOEXCEPT
Definition math.h:71
constexpr common_type_t< T, U > max(T a, U b) FL_NOEXCEPT
Definition math.h:75

References brightness, fl::max(), and fl::min().

Referenced by update().

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