FastLED 3.9.15
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:
79 explicit SpectralEqualizer(const SpectralEqualizerConfig& config);
81
84 void configure(const SpectralEqualizerConfig& config);
85
89 void apply(span<const float> inputBins, span<float> outputBins) const;
90
93 void setCustomGains(span<const float> gains);
94
97 span<const float> getGains() const { return mGains; }
98
100 const SpectralEqualizerConfig& getConfig() const { return mConfig; }
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 { return mStats; }
113
115 void resetStats();
116
117private:
119 void calculateGains();
120
123
125 void calculateFlatGains();
126
131 float calculateMakeupGain(span<const float> inputBins, span<const float> outputBins) const;
132
136 float applyCompression(float value) const;
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...
const SpectralEqualizerConfig & getConfig() const
Get current configuration.
void calculateGains()
Calculate gains based on current curve.
void setCustomGains(span< const float > gains)
Set custom per-band gains (switches to Custom curve)
void configure(const SpectralEqualizerConfig &config)
Configure the spectral equalizer This calculates per-band gain multipliers based on the selected curv...
~SpectralEqualizer() FL_NOEXCEPT
float calculateMakeupGain(span< const float > inputBins, span< const float > outputBins) const
Calculate makeup gain to maintain target level.
void calculateFlatGains()
Calculate flat gains (all 1.0)
void calculateAWeightingGains()
Calculate A-weighting gains.
void apply(span< const float > inputBins, span< float > outputBins) const
Apply equalization to frequency bins.
float applyCompression(float value) const
Apply dynamic range compression per band.
static constexpr float A_WEIGHTING_32BAND[32]
A-weighting coefficients for 32-band frequency analysis.
span< const float > getGains() const
Get current per-band gains.
SpectralEqualizerConfig mConfig
vector< float > mGains
Per-band gain multipliers.
Get statistics (for debugging/monitoring)
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.
constexpr int type_rank< T >::value
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT