FastLED 3.9.15
Loading...
Searching...
No Matches
signal_conditioner.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
14 bool enableDCRemoval = true;
15
17 bool enableSpikeFilter = true;
18
20 bool enableNoiseGate = true;
21
24 i16 spikeThreshold = 10000;
25
28
31
32 // DC removal uses per-buffer instantaneous calculation (no alpha needed)
33};
34
55public:
59
62
67
69 void reset() FL_NOEXCEPT;
70
72 struct Stats {
73 i32 dcOffset = 0; // Current DC offset estimate
74 bool noiseGateOpen = false; // Current noise gate state
75 u32 spikesRejected = 0; // Count of spikes rejected (lifetime)
76 u32 samplesProcessed = 0; // Total samples processed (lifetime)
77 };
78
79 const Stats& getStats() const FL_NOEXCEPT { return mStats; }
80
81private:
87
93
98 void removeDCOffset(span<const i16> pcm, i32 dcOffset, vector<i16>& output) FL_NOEXCEPT;
99
104
107
109 bool mNoiseGateOpen = false;
110
115};
116
117} // namespace audio
118} // namespace fl
void removeDCOffset(span< const i16 > pcm, i32 dcOffset, vector< i16 > &output) FL_NOEXCEPT
Remove DC offset from samples.
bool mNoiseGateOpen
Noise gate state.
i32 calculateDCOffset(span< const i16 > pcm, const vector< bool > &validMask) FL_NOEXCEPT
Calculate DC offset from valid samples only.
~SignalConditioner() FL_NOEXCEPT
vector< bool > mValidMask
Working buffers (reused to avoid allocations)
void applyNoiseGate(span< const i16 > pcm, vector< i16 > &output) FL_NOEXCEPT
Apply noise gate with hysteresis.
Sample processSample(const Sample &sample) FL_NOEXCEPT
Process a raw audio sample through the conditioning pipeline.
size filterSpikes(span< const i16 > pcm, vector< bool > &validMask) FL_NOEXCEPT
Detect and reject spike samples.
void configure(const SignalConditionerConfig &config) FL_NOEXCEPT
Configure the signal conditioner.
void reset() FL_NOEXCEPT
Reset internal state (DC estimate, noise gate state)
const Stats & getStats() const FL_NOEXCEPT
SignalConditionerConfig mConfig
Get current statistics (for debugging/monitoring)
bool enableDCRemoval
Enable DC offset removal (running average high-pass filter)
bool enableNoiseGate
Enable noise gate with hysteresis.
i16 noiseGateCloseThreshold
Noise gate close threshold (signal must fall below to close gate)
bool enableSpikeFilter
Enable spike filtering for I2S glitches.
i16 noiseGateOpenThreshold
Noise gate open threshold (signal must exceed to open gate)
i16 spikeThreshold
Spike detection threshold (absolute value) Samples beyond ±spikeThreshold are rejected as glitches.
Configuration for signal conditioning pipeline.
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
Definition sample.cpp.hpp:9
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT