FastLED 3.10.8
Loading...
Searching...
No Matches
spectral_equalizer.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/int.h"
4#include "fl/stl/vector.h"
5#include "fl/stl/span.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9namespace audio {
10
13 Flat, // No equalization (all gains = 1.0)
14 AWeighting, // A-weighting curve (emphasizes 1-6 kHz, de-emphasizes bass/treble)
15 Custom // User-defined per-band gains
16};
17
50
77public:
81
85
89 void apply(span<const float> inputBins, span<float> outputBins) const FL_NO_EXCEPT;
90
93 void setCustomGains(span<const float> gains) FL_NO_EXCEPT;
94
97 span<const float> getGains() const FL_NO_EXCEPT { return mGains; }
98
101
103 struct Stats {
104 u32 applicationsCount = 0; // Total applications performed
105 float lastInputPeak = 0.0f; // Peak value in last input
106 float lastOutputPeak = 0.0f; // Peak value in last output
107 float lastMakeupGain = 1.0f; // Makeup gain applied in last call
108 float avgInputLevel = 0.0f; // Average input level (last call)
109 float avgOutputLevel = 0.0f; // Average output level (last call)
110 };
111
112 const Stats& getStats() const FL_NO_EXCEPT { return mStats; }
113
116
117private:
120
123
126
131 float calculateMakeupGain(span<const float> inputBins, span<const float> outputBins) const FL_NO_EXCEPT;
132
136 float applyCompression(float value) const FL_NO_EXCEPT;
137
139 mutable Stats mStats;
140
143
147 static constexpr float A_WEIGHTING_16BAND[16] = {
148 0.5f, // Bin 0: 20-40 Hz (bass rolloff)
149 0.6f, // Bin 1: 40-80 Hz (bass rolloff)
150 0.8f, // Bin 2: 80-160 Hz (gradual increase)
151 1.0f, // Bin 3: 160-320 Hz (flat)
152 1.2f, // Bin 4: 320-640 Hz (emphasis begins)
153 1.3f, // Bin 5: 640-1280 Hz (emphasis)
154 1.4f, // Bin 6: 1280-2560 Hz (peak emphasis)
155 1.4f, // Bin 7: 2560-5120 Hz (peak emphasis)
156 1.3f, // Bin 8: 5120-10240 Hz (gradual rolloff)
157 1.2f, // Bin 9: 10240-16000 Hz (rolloff continues)
158 1.0f, // Bin 10 (fallback)
159 0.8f, // Bin 11 (fallback)
160 0.6f, // Bin 12 (fallback)
161 0.4f, // Bin 13 (fallback)
162 0.2f, // Bin 14 (fallback)
163 0.1f // Bin 15 (fallback)
164 };
165
167 static constexpr float A_WEIGHTING_32BAND[32] = {
168 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, // Bass rolloff (0-7)
169 1.1f, 1.2f, 1.3f, 1.4f, 1.4f, 1.4f, 1.3f, 1.2f, // Mid emphasis (8-15)
170 1.1f, 1.0f, 0.9f, 0.8f, 0.7f, 0.6f, 0.5f, 0.4f, // Treble rolloff (16-23)
171 0.3f, 0.2f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f // High freq rolloff (24-31)
172 };
173};
174
175} // namespace audio
176} // namespace fl
static constexpr float A_WEIGHTING_16BAND[16]
A-weighting coefficients for 16-band frequency analysis These approximate the A-weighting curve acros...
float applyCompression(float value) const FL_NO_EXCEPT
Apply dynamic range compression per band.
void configure(const SpectralEqualizerConfig &config) FL_NO_EXCEPT
Configure the spectral equalizer This calculates per-band gain multipliers based on the selected curv...
~SpectralEqualizer() FL_NO_EXCEPT
void calculateFlatGains() FL_NO_EXCEPT
Calculate flat gains (all 1.0)
void calculateAWeightingGains() FL_NO_EXCEPT
Calculate A-weighting gains.
void resetStats() FL_NO_EXCEPT
Reset statistics.
void apply(span< const float > inputBins, span< float > outputBins) const FL_NO_EXCEPT
Apply equalization to frequency bins.
const Stats & getStats() const FL_NO_EXCEPT
float calculateMakeupGain(span< const float > inputBins, span< const float > outputBins) const FL_NO_EXCEPT
Calculate makeup gain to maintain target level.
span< const float > getGains() const FL_NO_EXCEPT
Get current per-band gains.
void calculateGains() FL_NO_EXCEPT
Calculate gains based on current curve.
const SpectralEqualizerConfig & getConfig() const FL_NO_EXCEPT
Get current configuration.
static constexpr float A_WEIGHTING_32BAND[32]
A-weighting coefficients for 32-band frequency analysis.
void setCustomGains(span< const float > gains) FL_NO_EXCEPT
Set custom per-band gains (switches to Custom curve)
SpectralEqualizerConfig mConfig
vector< float > mGains
Per-band gain multipliers.
Get statistics (for debugging/monitoring)
#define constexpr
Declares that it is possible to evaluate a value at compile time, introduced in C++11.
Definition cpp_compat.h:15
EqualizationCurve
Equalization curve type.
EqualizationCurve curve
Equalization curve type.
float compressionThreshold
Compression threshold (0.0-1.0) Signals above this level are compressed.
bool enableCompression
Enable dynamic range compression per band Compresses loud signals to reduce dynamic range.
float makeupGainTarget
Makeup gain target level (0.0-1.0) The equalizer will scale output to maintain this average level.
bool applyMakeupGain
Apply makeup gain to compensate for overall level changes If true, automatically adjusts overall gain...
float compressionRatio
Compression ratio (1.0 = no compression, higher = more compression) 2.0 = 2:1 ratio,...
vector< float > customGains
Custom per-band gain multipliers (only used if curve = Custom) Size must match numBands.
size numBands
Number of frequency bands (must match FrequencyBinMapper output)
Configuration for spectral equalizer.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
constexpr int type_rank< T >::value
Base definition for an LED controller.
Definition crgb.hpp:179