FastLED 3.10.8
Loading...
Searching...
No Matches
dynamics_analyzer.h
Go to the documentation of this file.
1#pragma once
2
4#include "fl/stl/function.h"
5#include "fl/stl/vector.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9namespace audio {
10namespace detector {
11
12// DynamicsAnalyzer tracks loudness trends over time to detect crescendos,
13// diminuendos, and overall dynamic evolution.
14class DynamicsAnalyzer : public Detector {
15public:
18
19 // Detector interface
20 void update(shared_ptr<Context> context) FL_NO_EXCEPT override;
21 void fireCallbacks() FL_NO_EXCEPT override;
22 bool needsFFT() const FL_NO_EXCEPT override { return false; }
23 const char* getName() const FL_NO_EXCEPT override { return "DynamicsAnalyzer"; }
24 void reset() FL_NO_EXCEPT override;
25
26 // Callbacks (multiple listeners supported)
27 function_list<void()> onCrescendo; // Loudness increasing
28 function_list<void()> onDiminuendo; // Loudness decreasing
29 function_list<void(float trend)> onDynamicTrend; // Current trend (-1 to +1)
30 function_list<void(float compression)> onCompressionRatio; // Dynamic range compression
31
32 // Configuration
33 void setHistorySize(fl::size size) FL_NO_EXCEPT;
34 void setTrendThreshold(float threshold) FL_NO_EXCEPT;
35 void setSmoothingFactor(float alpha) FL_NO_EXCEPT;
36
37 // State access
38 float getDynamicTrend() const FL_NO_EXCEPT { return mTrend; }
39 float getCurrentRMS() const FL_NO_EXCEPT { return mCurrentRMS; }
40 float getAverageRMS() const FL_NO_EXCEPT { return mAverageRMS; }
41 float getPeakRMS() const FL_NO_EXCEPT { return mPeakRMS; }
43 bool isCrescendo() const FL_NO_EXCEPT { return mIsCrescendo; }
44 bool isDiminuendo() const FL_NO_EXCEPT { return mIsDiminuendo; }
45
46private:
48 fl::size mHistorySize;
49 fl::size mHistoryIndex;
50
53 float mPeakRMS;
54 float mMinRMS;
55 float mTrend;
60
65
67
69 void updatePeak(float rms) FL_NO_EXCEPT;
71};
72
73} // namespace detector
74} // namespace audio
75} // namespace fl
float rms(fl::span< const int16_t > data)
Definition simple.h:104
float getAverageRMS() const FL_NO_EXCEPT
float getDynamicTrend() const FL_NO_EXCEPT
void setSmoothingFactor(float alpha) FL_NO_EXCEPT
bool isDiminuendo() const FL_NO_EXCEPT
function_list< void(float compression)> onCompressionRatio
void update(shared_ptr< Context > context) FL_NO_EXCEPT override
const char * getName() const FL_NO_EXCEPT override
function_list< void(float trend)> onDynamicTrend
void setTrendThreshold(float threshold) FL_NO_EXCEPT
float getCompressionRatio() const FL_NO_EXCEPT
~DynamicsAnalyzer() FL_NO_EXCEPT override
bool isCrescendo() const FL_NO_EXCEPT
void setHistorySize(fl::size size) FL_NO_EXCEPT
float getCurrentRMS() const FL_NO_EXCEPT
float getPeakRMS() const FL_NO_EXCEPT
bool needsFFT() const FL_NO_EXCEPT override
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179