FastLED 3.9.15
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) override;
21 void fireCallbacks() override;
22 bool needsFFT() const override { return false; }
23 const char* getName() const override { return "DynamicsAnalyzer"; }
24 void reset() 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);
34 void setTrendThreshold(float threshold);
35 void setSmoothingFactor(float alpha);
36
37 // State access
38 float getDynamicTrend() const { return mTrend; }
39 float getCurrentRMS() const { return mCurrentRMS; }
40 float getAverageRMS() const { return mAverageRMS; }
41 float getPeakRMS() const { return mPeakRMS; }
42 float getCompressionRatio() const { return mCompressionRatio; }
43 bool isCrescendo() const { return mIsCrescendo; }
44 bool isDiminuendo() const { 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
68 float calculateTrend();
69 void updatePeak(float rms);
70 void updateCompression();
71};
72
73} // namespace detector
74} // namespace audio
75} // namespace fl
float rms(fl::span< const int16_t > data)
Definition simple.h:104
void update(shared_ptr< Context > context) override
~DynamicsAnalyzer() FL_NOEXCEPT override
function_list< void(float compression)> onCompressionRatio
function_list< void(float trend)> onDynamicTrend
const char * getName() const override
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT