MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/audio/deficiencies.cpp:29–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include "fl/math/math.h"
28
29FL_TEST_FILE(FL_FILEPATH) {
30
31using namespace fl;
32using Diag = fl::audio::detector::VocalDetectorDiagnostics;
33using fl::audio::test::makeSample;
34using fl::audio::test::generateDC;
35using fl::audio::test::generateSine;
36
37namespace {
38
39constexpr float PI = 3.14159265358979f;
40
41} // anonymous namespace
42
43// =============================================================================
44// 1. Signal conditioning SHOULD be enabled by default
45// =============================================================================
46// A user who creates an audio::Processor and calls update() should get
47// conditioned audio (DC removed, spikes filtered) without needing to know
48// about setSignalConditioningEnabled(). MEMS microphones like the INMP441
49// always have DC offset and occasional I2S glitches.
50
51FL_TEST_CASE("Audio fix - DC offset removed by default") {
52 audio::Processor processor;
53
54 // Sample with large DC offset (3000) — common with INMP441 MEMS mic
55 vector<i16> pcm;
56 generateSine(pcm, 512, 440.0f, 44100.0f, 5000);
57 // Add DC offset
58 for (auto& sample : pcm) {
59 i32 val = static_cast<i32>(sample) + 3000;
60 sample = static_cast<i16>(fl::max(-32768, fl::min(32767, val)));
61 }
62
63 processor.update(makeSample(pcm, 1000));
64
65 // Measure DC offset of the sample that reached detector
66 const auto &processed = processor.getSample().pcm();
67 i64 sum = 0;
68 for (size i = 0; i < processed.size(); ++i) {
69 sum += processed[i];
70 }
71 float meanDC =
72 static_cast<float>(sum) / static_cast<float>(processed.size());
73
74 // DESIRED: DC offset should be removed — mean should be near zero
75 FL_CHECK_LT(fl::abs(meanDC), 500.0f);
76}
77
78FL_TEST_CASE("Audio fix - I2S spike filtered by default") {
79 audio::Processor processor;
80
81 // Sample with a large spike (I2S glitch)
82 vector<i16> pcm;
83 generateDC(pcm, 512, 0);
84 pcm[100] = 30000; // spike well above normal signal range
85
86 processor.update(makeSample(pcm, 1000));

Callers

nothing calls this directly

Calls 15

maxFunction · 0.85
generateDCFunction · 0.85
sinfFunction · 0.85
setSmoothingMethod · 0.80
setSampleMethod · 0.80
setMinBPMMethod · 0.80
setMaxBPMMethod · 0.80
freqToBinMethod · 0.80
makeSampleFunction · 0.70
generateSineFunction · 0.50
absFunction · 0.50

Tested by

no test coverage detected