Skip to content

feat(audio): silence gate foundations — Context::isSilent() + SilenceEnvelope (#2253) - #2306

Merged
zackees merged 3 commits into
masterfrom
feat/audio-silence-gate
Apr 18, 2026
Merged

zackees merged 3 commits into
masterfrom
feat/audio-silence-gate

Conversation

@zackees

@zackees zackees commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1 of the fix for #2253 (audio volume not returning to zero in silence). Lays the architectural groundwork; no user-visible behavior change yet — Phase 2 PRs will adopt this in Vibe, Reactive spectral metrics, and TempoAnalyzer.

See docs/audio_silence_gate_design.md for the full design.

Two commits, each a self-contained unit:

1. Context::isSilent() plumbing

  • New setSilent/isSilent on audio::Context (default false, cleared on setSample())
  • Processor::update() and Reactive::processSample() populate it from NoiseFloorTracker::isAboveFloor() after the existing NFT update
  • No behavior change for users who haven't enabled NFT — isSilent() stays false

2. SilenceEnvelope helper class

  • Composable decay-to-target helper: pass-through during audio, exponential decay during silence, snap-back on re-attack (zero attack lag — beats must hit hard)
  • Frame-rate-independent (alpha = 1 - exp(-dt/tau))
  • Unit tests cover pass-through, decay curve, snap-back, isGated threshold, non-zero targets, degenerate tau=0

Why architecture-first

The survey (see design doc §Problem) found NoiseFloorTracker was already computing high-quality silence info but nothing read it. Phase 1 plugs that orphaned infrastructure into a shared bus (Context) and ships a reusable primitive so Phase 2 can be three small, parallelizable adoption PRs instead of three one-off patches.

Test plan

  • bash test fl_audio --debug — 211 tests pass under ASAN/UBSAN
  • bash lint on all touched files — clean
  • Phase 2 adoption: Vibe (PR-C), Reactive spectral metrics (PR-D), TempoAnalyzer (PR-E) — will reference this PR

Non-goals (explicitly out of scope)

  • Unified AudioLevel value type (considered — rejected as too churn-heavy for a bug fix; can layer on later)
  • Flipping NFT on by default (deferred to a separate PR with benchmarks)
  • Changes to signal conditioner

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added audio silence-gating infrastructure with smooth exponential decay during silent periods to improve detector behavior when audio is quiet.
  • Tests

    • Added unit tests validating silence-detection and smooth envelope decay behavior.
  • Documentation

    • Added design documentation for the audio silence-gating approach.

zackees and others added 3 commits April 18, 2026 07:08
Two-layer design for fixing volume-not-zero-in-silence:
1. Context::isSilent() — boolean flag populated from NoiseFloorTracker
2. SilenceEnvelope — reusable decay-to-target helper detectors compose

Phase 1 (parallelizable): Context plumbing + SilenceEnvelope class + tests.
Phase 2 (parallelizable): Vibe / Reactive spectral / TempoAnalyzer adopt.

No breaking changes; silence gating is strictly additive and opt-in via
existing NoiseFloorTracker enable flag.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds a frame-wide silence boolean on audio::Context that detectors can
read to gate their outputs when audio stops. Populated from
NoiseFloorTracker::isAboveFloor() by both Processor::update() and
Reactive::processSample() after their existing NFT update call.

Reset to false on setSample() so a stale claim can't survive a frame
where NFT is disabled or the pipeline owner forgets to populate it.

This is plumbing only — no detector consumes the flag yet. Default
behavior is unchanged: NFT is off by default, so isSilent() returns
false and detectors that check it simply won't gate. Users opt in via
Processor::enableNoiseFloorTracker(true) or ReactiveConfig.

Part of the fix for #2253 (volume not returning to zero).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
New fl::audio::SilenceEnvelope composable helper that detectors embed to
translate Context::isSilent() into smooth per-metric decay:

- Pass-through during audio (isSilent=false returns currentValue).
- Exponential decay toward Config::targetValue during silence; alpha =
  1 - exp(-dt / decayTauSeconds) gives a proper first-order response
  independent of frame rate.
- Snap-back on silence→audio transition: beats hit hard with zero
  attack lag, avoiding the classic compressor-release smear.
- isGated(epsilon) for "fully decayed" queries; reset(initial) for
  explicit jumps.

Registered in src/fl/audio/_build.cpp.hpp unity build. Unit tests at
tests/fl/audio/silence_envelope.hpp cover pass-through, decay curve
within 5% at 3*tau, snap-back, isGated threshold, non-zero targets,
and degenerate zero-tau behavior.

Ready for adoption by Vibe / Reactive spectral metrics / TempoAnalyzer
in Phase 2 of #2253.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces audio silence-gating functionality to the audio processing pipeline. It adds a per-frame silence boolean to audio::Context (populated from noise-floor tracking in Processor and Reactive), a new reusable SilenceEnvelope helper class that converts the silence flag into smooth exponential decay toward a target value, comprehensive design documentation, and full unit test coverage for both components.

Changes

Cohort / File(s) Summary
Design Documentation
docs/audio_silence_gate_design.md
New design document specifying two-layer audio silence-gating approach, including context plumbing strategy, SilenceEnvelope behavior, implementation phases (Phase 1: context + envelope; Phase 2: detector integration), testing plans, and open questions. Documentation-only; no code modifications.
Core Silence Envelope Implementation
src/fl/audio/silence_envelope.h, src/fl/audio/silence_envelope.cpp.hpp
New header-only SilenceEnvelope class converting boolean silence state into smooth per-metric decay. Features configurable exponential decay time constant (decayTauSeconds) and target value, pass-through behavior during active audio, snap-back on silence-to-audio transition, and isGated() threshold reporting.
Audio Context Silence Flag
src/fl/audio/audio_context.h, src/fl/audio/audio_context.cpp.hpp
Added per-frame mIsSilent flag with setSilent(bool) and isSilent() accessors. Flag defaults to false and automatically resets on setSample() calls to prevent stale silence claims across frames.
Audio Pipeline Integration
src/fl/audio/audio_processor.cpp.hpp, src/fl/audio/audio_reactive.cpp.hpp
Integrated silence-flag population derived from NoiseFloorTracker::isAboveFloor() in Processor::update (Stage 4) and Reactive::processSample, gated by noise-floor tracking enablement. Flag set after sample assignment but before detector updates.
Build & Test Infrastructure
src/fl/audio/_build.cpp.hpp, tests/fl/audio.cpp
Added compilation unit includes for new SilenceEnvelope component and corresponding test suite.
Unit Tests
tests/fl/audio/audio_context.hpp, tests/fl/audio/silence_envelope.hpp
Comprehensive test coverage: Context silence flag behavior (default, set, reset on sample); SilenceEnvelope pass-through during audio, exponential decay during silence, snap-back on transitions, gating threshold with configurable epsilon, convergence to non-zero targets, reset functionality, and instantaneous decay when decayTauSeconds == 0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Ears perked to catch the hush,
Where silence gates begin their rush,
Exponential decay divine,
Smoothing audio's quiet line,
No stale flags shall pass the gate—
Only fresh frames seal their fate! 🎙️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: introduction of Context::isSilent() and SilenceEnvelope as foundational components for audio silence gating.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/audio-silence-gate

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Header Compilation Performance

Total Time: 988.61ms

Top 5 Slowest Headers

  1. FastLED.h - 758.13ms
  2. fl/fastled.h - 320.60ms
  3. fl/task/executor.h - 252.53ms
  4. crgb.h - 180.99ms
  5. fl/gfx/crgb.h - 179.66ms

Warnings

⚠️ Header FastLED.h exceeds 150ms (758.1ms)
⚠️ Header fl/fastled.h exceeds 150ms (320.6ms)
⚠️ Header fl/task/executor.h exceeds 150ms (252.5ms)
⚠️ Header crgb.h exceeds 150ms (181.0ms)
⚠️ Header fl/gfx/crgb.h exceeds 150ms (179.7ms)
⚠️ Header fl/math/ease.h exceeds 150ms (175.0ms)
⚠️ Header fl/math/fixed_point.h exceeds 150ms (172.1ms)
⚠️ Header fl/task/scheduler.h exceeds 50ms (135.0ms)
⚠️ Header fl/stl/singleton.h exceeds 50ms (126.5ms)
⚠️ Header fl/stl/thread_local.h exceeds 50ms (125.9ms)
⚠️ Header fl/stl/thread.h exceeds 50ms (124.9ms)
⚠️ Header platforms/thread.h exceeds 50ms (124.8ms)
⚠️ Header platforms/stub/thread_stub.h exceeds 50ms (124.8ms)
⚠️ Header platforms/stub/thread_stub_stl.h exceeds 50ms (124.7ms)
⚠️ Header fl/task/promise.h exceeds 50ms (105.7ms)
⚠️ Header fl/ui.h exceeds 50ms (103.5ms)
⚠️ Header fl/stl/json.h exceeds 50ms (65.8ms)
⚠️ Header fl/stl/function.h exceeds 50ms (60.7ms)
⚠️ Header fl/stl/json/types.h exceeds 50ms (52.1ms)
⚠️ Template instantiation time is high (50.5%)

Full Report
================================================================================
FASTLED COMPILATION PERFORMANCE REPORT
================================================================================
Generated: 2026-04-18 14:09:49
Compiler: clang++-17
File: ci/perf/test_compile.cpp

SUMMARY
--------------------------------------------------------------------------------
Total Compilation Time:    2,099.86 ms
Frontend Time:             14.27 ms (0.7%)
Backend Time:              197.25 ms (9.4%)

COMPILATION PHASES
--------------------------------------------------------------------------------
Source                    13451.86 ms (640.6%)
Templates                   478.24 ms ( 22.8%)

FASTLED HEADERS (Level 1 - Direct Includes)
--------------------------------------------------------------------------------
  1573.7 ms - FastLED.h (SLOW)
   933.2 ms - fl/task/executor.h (SLOW)
   572.8 ms - fl/task/promise.h (SLOW)
   532.1 ms - fl/stl/function.h (SLOW)
   439.1 ms - fl/fastled.h (SLOW)
   348.7 ms - fl/task/scheduler.h (SLOW)
   340.5 ms - fl/stl/singleton.h (SLOW)
   339.9 ms - fl/stl/thread_local.h (SLOW)
   338.9 ms - fl/stl/thread.h (SLOW)
   338.8 ms - platforms/thread.h (SLOW)
   338.7 ms - platforms/stub/thread_stub.h (SLOW)
   338.7 ms - platforms/stub/thread_stub_stl.h (SLOW)
   331.6 ms - fl/stl/variant.h (SLOW)
   329.9 ms - fl/stl/new.h (SLOW)
   329.8 ms - platforms/new.h (SLOW)
   329.8 ms - platforms/shared/new.h (SLOW)
   266.5 ms - crgb.h (SLOW)
   265.3 ms - fl/gfx/crgb.h (SLOW)
   261.0 ms - fl/math/ease.h (SLOW)
   259.1 ms - fl/math/fixed_point.h (SLOW)

FASTLED HEADERS (Nested Includes - Up to 10 Levels)
--------------------------------------------------------------------------------
FastLED.h (1573.7ms)
  ├─  933.2 ms - fl/task/executor.h
  │ ├─  572.8 ms - fl/task/promise.h
  │ │ ├─  532.1 ms - fl/stl/function.h
  │ │ │ ├─  331.6 ms - fl/stl/variant.h
  │ │ │ │ └─  329.9 ms - fl/stl/new.h
  │ │ │ │   └─  329.8 ms - platforms/new.h
  │ │ │ │     └─  329.8 ms - platforms/shared/new.h
  │ │ │ │       └─  204.2 ms - new
  │ │ │ │         ├─   57.0 ms - c++config.h
  │ │ │ │         │ └─    6.2 ms - os_defines.h
  │ │ │ │         └─    1.3 ms - version.h
  │ │ │ ├─  121.4 ms - fl/stl/vector.h
  │ │ │ │ ├─   77.4 ms - fl/math/math.h
  │ │ │ │ │ └─   72.9 ms - fl/stl/undef.h
  │ │ │ │ │   └─  102.9 ms - stdlib.h
  │ │ │ │ │     ├─   50.0 ms - cstdlib
  │ │ │ │ │     │ ├─  102.9 ms - stdlib.h
  │ │ │ │ │     │ │ ├─   50.0 ms - cstdlib
  │ │ │ │ │     │ │ └─    9.5 ms - types.h
  │ │ │ │ │     │ └─    0.6 ms - std_abs.h
  │ │ │ │ │     └─    9.5 ms - types.h
  │ │ │ │ │       ├─    9.5 ms - types.h
  │ │ │ │ │       │ ├─    9.5 ms - types.h
  │ │ │ │ │       │ ├─    1.9 ms - pthreadtypes.h
  │ │ │ │ │       │ ├─    1.6 ms - endian.h
  │ │ │ │ │       │ └─    1.5 ms - select.h
  │ │ │ │ │       ├─    1.9 ms - pthreadtypes.h
  │ │ │ │ │       │ └─    1.5 ms - thread-shared-types.h
  │ │ │ │ │       ├─    1.6 ms - endian.h
  │ │ │ │ │       └─    1.5 ms - select.h
  │ │ │ │ ├─   17.4 ms - fl/stl/initializer_list.h
  │ │ │ │ ├─   16.6 ms - fl/stl/allocator.h
  │ │ │ │ │ └─   10.9 ms - fl/stl/bitset.h
  │ │ │ │ │   └─    7.2 ms - fl/stl/bitset_dynamic.h
  │ │ │ │ │     └─    1.8 ms - fl/stl/unique_ptr.h
  │ │ │ │ ├─    2.4 ms - fl/stl/basic_vector.h
  │ │ │ │ └─    0.6 ms - fl/stl/functional.h
  │ │ │ ├─   65.3 ms - fl/stl/shared_ptr.h
  │ │ │ │ ├─   51.4 ms - fl/stl/type_traits.h
  │ │ │ │ │ └─   45.9 ms - fl/stl/move.h
  │ │ │ │ ├─    9.5 ms - fl/stl/atomic.h
  │ │ │ │ │ └─    8.5 ms - platforms/atomic.h
  │ │ │ │ │   └─    8.5 ms - platforms/shared/atomic.h
  │ │ │ │ └─    0.6 ms - fl/stl/bit_cast.h
  │ │ │ ├─    5.2 ms - fl/stl/compiler_control.h
  │ │ │ └─    3.8 ms - fl/stl/algorithm.h
  │ │ │   └─    1.6 ms - fl/math/random.h
  │ │ │     └─    0.8 ms - fl/math/random8.h
  │ │ └─   36.0 ms - fl/stl/string.h
  │ │   ├─   10.8 ms - fl/stl/basic_string.h
  │ │   │ ├─    0.8 ms - fl/stl/not_null.h
  │ │   │ └─    0.8 ms - fl/stl/iterator.h
  │ │   ├─    7.1 ms - fl/stl/span.h
  │ │   │ └─    2.9 ms - fl/math/geometry.h
  │ │   ├─    4.3 ms - fl/stl/string_view.h
  │ │   └─    1.3 ms - fl/stl/optional.h
  │ ├─  348.7 ms - fl/task/scheduler.h
  │ │ ├─  340.5 ms - fl/stl/singleton.h
  │ │ │ └─  339.9 ms - fl/stl/thread_local.h
  │ │ │   └─  338.9 ms - fl/stl/thread.h
  │ │ │     └─  338.8 ms - platforms/thread.h
  │ │ │       └─  338.7 ms - platforms/stub/thread_stub.h
  │ │ │         └─  338.7 ms - platforms/stub/thread_stub_stl.h
  │ │ │           └─  333.0 ms - thread
  │ │ │             ├─  193.6 ms - std_thread.h
  │ │ │             └─  120.6 ms - this_thread_sleep.h
  │ │ └─    7.5 ms - fl/task/task.h
  │ │   └─    2.9 ms - fl/trace.h
  │ │     ├─    1.8 ms - fl/stl/chrono.h
  │ │     └─    0.8 ms - fl/stl/tuple.h
  │ ├─    9.8 ms - platforms/await.h
  │ │ └─    9.5 ms - platforms/coroutine_runtime.h
  │ │   └─    8.1 ms - fl/system/engine_events.h
  │ │     ├─    4.1 ms - fl/math/screenmap.h
  │ │     │ └─    3.0 ms - fl/stl/flat_map.h
  │ │     └─    2.6 ms - fl/math/xymap.h
  │ │       └─    0.7 ms - fl/math/lut.h
  │ └─    0.6 ms - fl/task/promise_result.h
  ├─  439.1 ms - fl/fastled.h
  │ ├─  266.5 ms - crgb.h
  │ │ ├─  265.3 ms - fl/gfx/crgb.h
  │ │ │ └─  261.0 ms - fl/math/ease.h
  │ │ │   └─  259.1 ms - fl/math/fixed_point.h
  │ │ │     ├─  142.3 ms - fl/math/fixed_point/s4x12.h
  │ │ │     │ ├─  126.1 ms - fl/math/sin32.h
  │ │ │     │ │ └─  123.6 ms - fl/math/simd.h
  │ │ │     │ │   └─  123.1 ms - fl/math/simd/types.h
  │ │ │     │ │     └─  122.8 ms - platforms/simd.h
  │ │ │     │ ├─    0.8 ms - fl/math/fixed_point/traits.h
  │ │ │     │ └─    0.6 ms - fl/math/fixed_point/isqrt.h
  │ │ │     ├─   14.7 ms - fl/math/fixed_point/s8x8.h
  │ │ │     ├─   14.5 ms - fl/math/fixed_point/s8x24.h
  │ │ │     ├─   14.3 ms - fl/math/fixed_point/s16x16.h
  │ │ │     └─   14.3 ms - fl/math/fixed_point/s24x8.h
  │ │ └─    0.8 ms - chsv.h
  │ │   └─    0.7 ms - fl/gfx/hsv.h
  │ ├─   85.1 ms - platforms.h
  │ │ └─   85.0 ms - platforms/stub/fastled_stub.h
  │ │   ├─   50.2 ms - platforms/stub/fastspi_stub.h
  │ │   │ └─   50.2 ms - platforms/stub/fastspi_stub_generic.h
  │ │   │   ├─   43.7 ms - platforms/shared/active_strip_data/active_strip_data.h
  │ │   │   │ └─   41.3 ms - fl/id_tracker.h
  │ │   │   │   └─   40.4 ms - fl/stl/mutex.h
  │ │   │   │     └─   40.3 ms - platforms/mutex.h
  │ │   │   │       └─   40.2 ms - platforms/stub/mutex_stub.h
  │ │   │   └─    5.9 ms - platforms/shared/active_strip_tracker/active_strip_tracker.h
  │ │   └─   34.7 ms - platforms/stub/clockless_stub.h
  │ │     └─   34.7 ms - platforms/stub/clockless_channel_stub.h
  │ │       ├─   15.1 ms - fl/channels/data.h
  │ │       │ └─   12.2 ms - fl/channels/config.h
  │ │       │   ├─    2.7 ms - fl/chipsets/chipset_timing_config.h
  │ │       │   │ └─    1.5 ms - fl/chipsets/led_timing.h
  │ │       │   └─    2.1 ms - fl/chipsets/spi.h
  │ │       ├─   10.3 ms - fl/system/log.h
  │ │       │ └─    9.9 ms - fl/stl/strstream.h
  │ │       ├─    2.1 ms - fl/channels/manager.h
  │ │       ├─    1.3 ms - fl/stl/weak_ptr.h
  │ │       └─    1.0 ms - fl/channels/driver.h
  │ ├─   33.2 ms - colorutils.h
  │ │ └─   32.4 ms - fl/gfx/colorutils.h
  │ │   ├─    7.0 ms - fl/gfx/blur.h
  │ │   │ └─    3.8 ms - fl/gfx/canvas.h
  │ │   │   └─    2.3 ms - fl/math/alpha.h
  │ │   └─    2.6 ms - fl/gfx/fill.h
  │ ├─   18.9 ms - pixel_controller.h
  │ │ ├─   13.3 ms - pixel_iterator.h
  │ │ │ └─   13.2 ms - fl/chipsets/encoders/pixel_iterator.h
  │ │ │   ├─    3.8 ms - fl/chipsets/encoders/apa102.h
  │ │ │   │ └─    3.0 ms - fl/chipsets/encoders/encoder_utils.h
  │ │ │   │   └─    2.5 ms - fl/gfx/gamma_lut.h
  │ │ │   ├─    3.6 ms - fl/chipsets/encoders/pixel_iterator_adapters.h
  │ │ │   ├─    0.8 ms - fl/chipsets/encoders/sk9822.h
  │ │ │   └─    0.7 ms - fl/chipsets/encoders/hd108.h
  │ │ └─    2.2 ms - rgbw.h
  │ │   └─    2.0 ms - fl/gfx/rgbw.h
  │ └─   17.0 ms - pixeltypes.h
  │   ├─   14.2 ms - lib8tion.h
  │   │ ├─    7.2 ms - fl/math/math8.h
  │   │ │ ├─    3.7 ms - fl/math/intmap.h
  │   │ │ │ └─    2.9 ms - platforms/intmap.h
  │   │ │ ├─    1.9 ms - fl/math/scale8.h
  │   │ │ │ └─    1.8 ms - platforms/scale8.h
  │   │ │ │   └─    0.8 ms - platforms/shared/scale8.h
  │   │ │ └─    1.5 ms - platforms/math8.h
  │   │ │   └─    1.2 ms - platforms/shared/math8.h
  │   │ └─    1.5 ms - fl/math/beat.h
  │   │   └─    0.8 ms - fl/math/trig8.h
  │   │     └─    0.8 ms - platforms/trig8.h
  │   │       └─    0.7 ms - platforms/shared/trig8.h
  │   └─    2.5 ms - crgb.hpp
  ├─  100.5 ms - fl/ui.h
  │ ├─   63.4 ms - fl/stl/json.h
  │ │ └─   49.9 ms - fl/stl/json/types.h
  │ │   └─    5.6 ms - fl/stl/limits.h
  │ ├─    9.1 ms - fl/ui_impl.h
  │ │ └─    8.5 ms - platforms/ui_defs.h
  │ │   ├─    1.9 ms - platforms/shared/ui/json/audio.h
  │ │   │ └─    0.9 ms - platforms/shared/ui/json/audio_internal.h
  │ │   ├─    1.4 ms - platforms/shared/ui/json/button.h
  │ │   │ └─    0.5 ms - platforms/shared/ui/json/ui_internal.h
  │ │   ├─    0.8 ms - platforms/shared/ui/json/checkbox.h
  │ │   ├─    0.8 ms - platforms/shared/ui/json/help.h
  │ │   └─    0.7 ms - platforms/shared/ui/json/number_field.h
  │ └─    5.4 ms - fl/stl/url.h
  ├─   23.7 ms - chipsets.h
  │ ├─    9.7 ms - fl/chipsets/ucs7604.h
  │ │ └─    7.4 ms - fl/chipsets/encoders/ucs7604.h
  │ ├─    5.6 ms - fl/chipsets/apa102.h
  │ ├─    1.5 ms - fl/chipsets/lpd880x.h
  │ ├─    0.8 ms - fl/chipsets/encoders/ws2816.h
  │ └─    0.7 ms - fl/chipsets/p9813.h
  └─   19.7 ms - fl/stl/stdint.h
    └─   19.4 ms - platforms/int.h
      └─   19.1 ms - platforms/shared/int.h
        └─   19.0 ms - platforms/shared/int_linux.h
fl/task/executor.h (933.2ms)
  ├─  572.8 ms - fl/task/promise.h
  │ ├─  532.1 ms - fl/stl/function.h
  │ │ ├─  331.6 ms - fl/stl/variant.h
  │ │ │ └─  329.9 ms - fl/stl/new.h
  │ │ │   └─  329.8 ms - platforms/new.h
  │ │ │     └─  329.8 ms - platforms/shared/new.h
  │ │ │       └─  204.2 ms - new
  │ │ │         ├─   57.0 ms - c++config.h
  │ │ │         │ └─    6.2 ms - os_defines.h
  │ │ │         │   └─    5.6 ms - features.h
  │ │ │         └─    1.3 ms - version.h
  │ │ ├─  121.4 ms - fl/stl/vector.h
  │ │ │ ├─   77.4 ms - fl/math/math.h
  │ │ │ │ └─   72.9 ms - fl/stl/undef.h
  │ │ │ │   └─  102.9 ms - stdlib.h
  │ │ │ │     ├─   50.0 ms - cstdlib
  │ │ │ │     │ ├─  102.9 ms - stdlib.h
  │ │ │ │     │ │ ├─   50.0 ms - cstdlib
  │ │ │ │     │ │ │ ├─  102.9 ms - stdlib.h
  │ │ │ │     │ │ │ └─    0.6 ms - std_abs.h
  │ │ │ │     │ │ └─    9.5 ms - types.h
  │ │ │ │     │ │   ├─    9.5 ms - types.h
  │ │ │ │     │ │   ├─    1.9 ms - pthreadtypes.h
  │ │ │ │     │ │   ├─    1.6 ms - endian.h
  │ │ │ │     │ │   └─    1.5 ms - select.h
  │ │ │ │     │ └─    0.6 ms - std_abs.h
  │ │ │ │     └─    9.5 ms - types.h
  │ │ │ │       ├─    9.5 ms - types.h
  │ │ │ │       │ ├─    9.5 ms - types.h
  │ │ │ │       │ │ ├─    9.5 ms - types.h
  │ │ │ │       │ │ ├─    1.9 ms - pthreadtypes.h
  │ │ │ │       │ │ ├─    1.6 ms - endian.h
  │ │ │ │       │ │ └─    1.5 ms - select.h
  │ │ │ │       │ ├─    1.9 ms - pthreadtypes.h
  │ │ │ │       │ │ └─    1.5 ms - thread-shared-types.h
  │ │ │ │       │ ├─    1.6 ms - endian.h
  │ │ │ │       │ └─    1.5 ms - select.h
  │ │ │ │       ├─    1.9 ms - pthreadtypes.h
  │ │ │ │       │ └─    1.5 ms - thread-shared-types.h
  │ │ │ │       ├─    1.6 ms - endian.h
  │ │ │ │       └─    1.5 ms - select.h
  │ │ │ ├─   17.4 ms - fl/stl/initializer_list.h
  │ │ │ ├─   16.6 ms - fl/stl/allocator.h
  │ │ │ │ └─   10.9 ms - fl/stl/bitset.h
  │ │ │ │   └─    7.2 ms - fl/stl/bitset_dynamic.h
  │ │ │ │     └─    1.8 ms - fl/stl/unique_ptr.h
  │ │ │ ├─    2.4 ms - fl/stl/basic_vector.h
  │ │ │ └─    0.6 ms - fl/stl/functional.h
  │ │ ├─   65.3 ms - fl/stl/shared_ptr.h
  │ │ │ ├─   51.4 ms - fl/stl/type_traits.h
  │ │ │ │ └─   45.9 ms - fl/stl/move.h
  │ │ │ ├─    9.5 ms - fl/stl/atomic.h
  │ │ │ │ └─    8.5 ms - platforms/atomic.h
  │ │ │ │   └─    8.5 ms - platforms/shared/atomic.h
  │ │ │ └─    0.6 ms - fl/stl/bit_cast.h
  │ │ ├─    5.2 ms - fl/stl/compiler_control.h
  │ │ └─    3.8 ms - fl/stl/algorithm.h
  │ │   └─    1.6 ms - fl/math/random.h
  │ │     └─    0.8 ms - fl/math/random8.h
  │ └─   36.0 ms - fl/stl/string.h
  │   ├─   10.8 ms - fl/stl/basic_string.h
  │   │ ├─    0.8 ms - fl/stl/not_null.h
  │   │ └─    0.8 ms - fl/stl/iterator.h
  │   ├─    7.1 ms - fl/stl/span.h
  │   │ └─    2.9 ms - fl/math/geometry.h
  │   ├─    4.3 ms - fl/stl/string_view.h
  │   └─    1.3 ms - fl/stl/optional.h
  ├─  348.7 ms - fl/task/scheduler.h
  │ ├─  340.5 ms - fl/stl/singleton.h
  │ │ └─  339.9 ms - fl/stl/thread_local.h
  │ │   └─  338.9 ms - fl/stl/thread.h
  │ │     └─  338.8 ms - platforms/thread.h
  │ │       └─  338.7 ms - platforms/stub/thread_stub.h
  │ │         └─  338.7 ms - platforms/stub/thread_stub_stl.h
  │ │           └─  333.0 ms - thread
  │ │             ├─  193.6 ms - std_thread.h
  │ │             │ ├─   58.2 ms - tuple
  │ │             │ ├─   44.1 ms - refwrap.h
  │ │             │ ├─   28.8 ms - iosfwd
  │ │             │ ├─   10.5 ms - gthr.h
  │ │             │ └─    5.5 ms - unique_ptr.h
  │ │             └─  120.6 ms - this_thread_sleep.h
  │ │               ├─  104.4 ms - chrono.h
  │ │               └─    5.0 ms - cerrno
  │ └─    7.5 ms - fl/task/task.h
  │   └─    2.9 ms - fl/trace.h
  │     ├─    1.8 ms - fl/stl/chrono.h
  │     └─    0.8 ms - fl/stl/tuple.h
  ├─    9.8 ms - platforms/await.h
  │ └─    9.5 ms - platforms/coroutine_runtime.h
  │   └─    8.1 ms - fl/system/engine_events.h
  │     ├─    4.1 ms - fl/math/screenmap.h
  │     │ └─    3.0 ms - fl/stl/flat_map.h
  │     └─    2.6 ms - fl/math/xymap.h
  │       └─    0.7 ms - fl/math/lut.h
  └─    0.6 ms - fl/task/promise_result.h
fl/fastled.h (439.1ms)
  ├─  266.5 ms - crgb.h
  │ ├─  265.3 ms - fl/gfx/crgb.h
  │ │ └─  261.0 ms - fl/math/ease.h
  │ │   └─  259.1 ms - fl/math/fixed_point.h
  │ │     ├─  142.3 ms - fl/math/fixed_point/s4x12.h
  │ │     │ ├─  126.1 ms - fl/math/sin32.h
  │ │     │ │ └─  123.6 ms - fl/math/simd.h
  │ │     │ │   └─  123.1 ms - fl/math/simd/types.h
  │ │     │ │     └─  122.8 ms - platforms/simd.h
  │ │     │ │       └─  122.8 ms - platforms/shared/simd_x86.hpp
  │ │     │ ├─    0.8 ms - fl/math/fixed_point/traits.h
  │ │     │ └─    0.6 ms - fl/math/fixed_point/isqrt.h
  │ │     ├─   14.7 ms - fl/math/fixed_point/s8x8.h
  │ │     ├─   14.5 ms - fl/math/fixed_point/s8x24.h
  │ │     ├─   14.3 ms - fl/math/fixed_point/s16x16.h
  │ │     └─   14.3 ms - fl/math/fixed_point/s24x8.h
  │ └─    0.8 ms - chsv.h
  │   └─    0.7 ms - fl/gfx/hsv.h
  ├─   85.1 ms - platforms.h
  │ └─   85.0 ms - platforms/stub/fastled_stub.h
  │   ├─   50.2 ms - platforms/stub/fastspi_stub.h
  │   │ └─   50.2 ms - platforms/stub/fastspi_stub_generic.h
  │   │   ├─   43.7 ms - platforms/shared/active_strip_data/active_strip_data.h
  │   │   │ └─   41.3 ms - fl/id_tracker.h
  │   │   │   └─   40.4 ms - fl/stl/mutex.h
  │   │   │     └─   40.3 ms - platforms/mutex.h
  │   │   │       └─   40.2 ms - platforms/stub/mutex_stub.h
  │   │   │         └─   40.2 ms - platforms/stub/mutex_stub_stl.h
  │   │   └─    5.9 ms - platforms/shared/active_strip_tracker/active_strip_tracker.h
  │   └─   34.7 ms - platforms/stub/clockless_stub.h
  │     └─   34.7 ms - platforms/stub/clockless_channel_stub.h
  │       ├─   15.1 ms - fl/channels/data.h
  │       │ └─   12.2 ms - fl/channels/config.h
  │       │   ├─    2.7 ms - fl/chipsets/chipset_timing_config.h
  │       │   │ └─    1.5 ms - fl/chipsets/led_timing.h
  │       │   └─    2.1 ms - fl/chipsets/spi.h
  │       ├─   10.3 ms - fl/system/log.h
  │       │ └─    9.9 ms - fl/stl/strstream.h
  │       ├─    2.1 ms - fl/channels/manager.h
  │       ├─    1.3 ms - fl/stl/weak_ptr.h
  │       └─    1.0 ms - fl/channels/driver.h
  ├─   33.2 ms - colorutils.h
  │ └─   32.4 ms - fl/gfx/colorutils.h
  │   ├─    7.0 ms - fl/gfx/blur.h
  │   │ └─    3.8 ms - fl/gfx/canvas.h
  │   │   └─    2.3 ms - fl/math/alpha.h
  │   └─    2.6 ms - fl/gfx/fill.h
  ├─   18.9 ms - pixel_controller.h
  │ ├─   13.3 ms - pixel_iterator.h
  │ │ └─   13.2 ms - fl/chipsets/encoders/pixel_iterator.h
  │ │   ├─    3.8 ms - fl/chipsets/encoders/apa102.h
  │ │   │ └─    3.0 ms - fl/chipsets/encoders/encoder_utils.h
  │ │   │   └─    2.5 ms - fl/gfx/gamma_lut.h
  │ │   ├─    3.6 ms - fl/chipsets/encoders/pixel_iterator_adapters.h
  │ │   ├─    0.8 ms - fl/chipsets/encoders/sk9822.h
  │ │   └─    0.7 ms - fl/chipsets/encoders/hd108.h
  │ └─    2.2 ms - rgbw.h
  │   └─    2.0 ms - fl/gfx/rgbw.h
  └─   17.0 ms - pixeltypes.h
    ├─   14.2 ms - lib8tion.h
    │ ├─    7.2 ms - fl/math/math8.h
    │ │ ├─    3.7 ms - fl/math/intmap.h
    │ │ │ └─    2.9 ms - platforms/intmap.h
    │ │ ├─    1.9 ms - fl/math/scale8.h
    │ │ │ └─    1.8 ms - platforms/scale8.h
    │ │ │   └─    0.8 ms - platforms/shared/scale8.h
    │ │ └─    1.5 ms - platforms/math8.h
    │ │   └─    1.2 ms - platforms/shared/math8.h
    │ └─    1.5 ms - fl/math/beat.h
    │   └─    0.8 ms - fl/math/trig8.h
    │     └─    0.8 ms - platforms/trig8.h
    │       └─    0.7 ms - platforms/shared/trig8.h
    └─    2.5 ms - crgb.hpp
fl/ui.h (100.5ms)
  ├─   63.4 ms - fl/stl/json.h
  │ └─   49.9 ms - fl/stl/json/types.h
  │   └─    5.6 ms - fl/stl/limits.h
  ├─    9.1 ms - fl/ui_impl.h
  │ └─    8.5 ms - platforms/ui_defs.h
  │   ├─    1.9 ms - platforms/shared/ui/json/audio.h
  │   │ └─    0.9 ms - platforms/shared/ui/json/audio_internal.h
  │   ├─    1.4 ms - platforms/shared/ui/json/button.h
  │   │ └─    0.5 ms - platforms/shared/ui/json/ui_internal.h
  │   ├─    0.8 ms - platforms/shared/ui/json/checkbox.h
  │   ├─    0.8 ms - platforms/shared/ui/json/help.h
  │   └─    0.7 ms - platforms/shared/ui/json/number_field.h
  └─    5.4 ms - fl/stl/url.h
chipsets.h (23.7ms)
  ├─    9.7 ms - fl/chipsets/ucs7604.h
  │ └─    7.4 ms - fl/chipsets/encoders/ucs7604.h
  ├─    5.6 ms - fl/chipsets/apa102.h
  ├─    1.5 ms - fl/chipsets/lpd880x.h
  ├─    0.8 ms - fl/chipsets/encoders/ws2816.h
  └─    0.7 ms - fl/chipsets/p9813.h

TOP 20 SLOWEST OPERATIONS
--------------------------------------------------------------------------------
  1.  1573.7 ms - Source: FastLED.h
  2.  1573.7 ms - Total Source: 
  3.   933.2 ms - Source: fl/task/executor.h
  4.   572.8 ms - Source: fl/task/promise.h
  5.   541.0 ms - Total ParseClass: 
  6.   532.1 ms - Source: fl/stl/function.h
  7.   439.1 ms - Source: fl/fastled.h
  8.   348.7 ms - Source: fl/task/scheduler.h
  9.   340.5 ms - Source: fl/stl/singleton.h
 10.   339.9 ms - Source: fl/stl/thread_local.h
 11.   338.9 ms - Source: fl/stl/thread.h
 12.   338.8 ms - Source: platforms/thread.h
 13.   338.7 ms - Source: platforms/stub/thread_stub.h
 14.   338.7 ms - Source: platforms/stub/thread_stub_stl.h
 15.   333.0 ms - Source: thread
 16.   331.6 ms - Source: fl/stl/variant.h
 17.   329.9 ms - Source: fl/stl/new.h
 18.   329.8 ms - Source: platforms/new.h
 19.   329.8 ms - Source: platforms/shared/new.h
 20.   266.5 ms - Source: crgb.h

PERFORMANCE FLAGS
--------------------------------------------------------------------------------
⚠️  SLOW HEADERS (>50.0ms):
    - FastLED.h (1573.7ms)
    - fl/task/executor.h (933.2ms)
    - fl/task/promise.h (572.8ms)
    - fl/stl/function.h (532.1ms)
    - fl/fastled.h (439.1ms)
    - fl/task/scheduler.h (348.7ms)
    - fl/stl/singleton.h (340.5ms)
    - fl/stl/thread_local.h (339.9ms)
    - fl/stl/thread.h (338.9ms)
    - platforms/thread.h (338.8ms)

⚠️  Template instantiation time is high (22.8% of total)
✓  Lexing time is acceptable (<10% of total)

RECOMMENDATIONS
--------------------------------------------------------------------------------
1. Consider optimizing FastLED.h (1573.7ms)
2. Consider optimizing fl/task/executor.h (933.2ms)
3. Consider optimizing fl/task/promise.h (572.8ms)

================================================================================

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (4)
src/fl/audio/audio_reactive.cpp.hpp (1)

168-183: Minor: avoid computing processedSample.rms() twice.

rms() is called at L171 for NoiseFloorTracker::update() and again at L181 for the silence check. Depending on whether Sample::rms() is cached or recomputed per call, this could be wasteful. Caching locally also keeps the two NFT calls consistent if rms() ever becomes non-idempotent.

Proposed refactor
-    // Step 2: Noise floor tracking (update tracker, but don't modify signal)
-    if (mConfig.enableNoiseFloorTracking) {
-        float rms = processedSample.rms();
-        mNoiseFloorTracker.update(rms);
-    }
-
-    // Set conditioned sample on shared Context (clears per-frame FFT cache)
-    mContext->setSample(processedSample);
-
-    // Populate silence flag after setSample() resets it — detectors run via
-    // updateFromContext() below and will read context->isSilent().
-    if (mConfig.enableNoiseFloorTracking) {
-        mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(processedSample.rms()));
-    }
+    // Step 2: Noise floor tracking (update tracker, but don't modify signal)
+    const bool nftEnabled = mConfig.enableNoiseFloorTracking;
+    float rms = 0.0f;
+    if (nftEnabled) {
+        rms = processedSample.rms();
+        mNoiseFloorTracker.update(rms);
+    }
+
+    // Set conditioned sample on shared Context (clears per-frame FFT cache)
+    mContext->setSample(processedSample);
+
+    // Populate silence flag after setSample() resets it — detectors run via
+    // updateFromContext() below and will read context->isSilent().
+    if (nftEnabled) {
+        mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(rms));
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/audio/audio_reactive.cpp.hpp` around lines 168 - 183, The code calls
processedSample.rms() twice; compute it once and reuse it to avoid redundant
work and ensure consistency: inside the block gated by
mConfig.enableNoiseFloorTracking, call Sample::rms() once into a local float
(e.g. rms), pass that to mNoiseFloorTracker.update(rms), then later use the same
rms when calling mNoiseFloorTracker.isAboveFloor(...) to set
mContext->setSilent(...); keep the conditional checks around
mConfig.enableNoiseFloorTracking and preserve the call to
mContext->setSample(processedSample).
src/fl/audio/audio_context.cpp.hpp (1)

164-171: Consider resetting mIsSilent in clearCache() for consistency.

setSample() clears the silence flag but clearCache() does not. After a full reset the flag could retain a stale true value from a prior frame until the next setSample() call. Low-impact since the pipeline always calls setSample() each frame, but worth fixing for defensive consistency.

Proposed tweak
 void Context::clearCache() {
     mFFTCache.clear();
     mFFTCacheMap.clear();
     mRecyclePool.clear();
     mFFTHistory.clear();
     mFFTHistoryDepth = 0;
     mFFTHistoryIndex = 0;
+    mIsSilent = false;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/audio/audio_context.cpp.hpp` around lines 164 - 171, The clearCache
routine (Context::clearCache) currently clears FFT caches and history but does
not reset the silence flag mIsSilent, which can leave a stale true value until
setSample runs; update Context::clearCache to also set mIsSilent = false so the
context is fully reset (mirror the behavior from setSample) ensuring defensive
consistency after a full reset.
src/fl/audio/audio_processor.cpp.hpp (1)

56-68: Minor: redundant conditioned.rms() call.

Same pattern as in Reactive::processSample: rms() is evaluated at L58 for NFT::update() and again at L67 for the silence gate. Cache the value locally to avoid the duplicate call and guarantee both NFT calls see the exact same value.

Proposed refactor
-    // Stage 3: Noise floor tracking (passive — updates estimate but doesn't modify signal)
-    if (mNoiseFloorTrackingEnabled && conditioned.isValid()) {
-        mNoiseFloorTracker.update(conditioned.rms());
-    }
-
-    mContext->setSample(conditioned);
-
-    // Stage 4: Silence flag — detectors use this to gate outputs when audio stops.
-    // Only populated when NFT is enabled; otherwise silence is unknowable and
-    // stays at its default (false) after setSample() above.
-    if (mNoiseFloorTrackingEnabled && conditioned.isValid()) {
-        mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(conditioned.rms()));
-    }
+    // Stage 3: Noise floor tracking (passive — updates estimate but doesn't modify signal)
+    const bool nftActive = mNoiseFloorTrackingEnabled && conditioned.isValid();
+    float condRms = 0.0f;
+    if (nftActive) {
+        condRms = conditioned.rms();
+        mNoiseFloorTracker.update(condRms);
+    }
+
+    mContext->setSample(conditioned);
+
+    // Stage 4: Silence flag — detectors use this to gate outputs when audio stops.
+    // Only populated when NFT is enabled; otherwise silence is unknowable and
+    // stays at its default (false) after setSample() above.
+    if (nftActive) {
+        mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(condRms));
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/audio/audio_processor.cpp.hpp` around lines 56 - 68, The code calls
conditioned.rms() twice (once for mNoiseFloorTracker.update and again for
mContext->setSilent), which is redundant and may yield slightly different
values; compute float rms = conditioned.rms() once after verifying
conditioned.isValid() and reuse it in mNoiseFloorTracker.update(rms) and
mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(rms)), keeping the same
guard (mNoiseFloorTrackingEnabled && conditioned.isValid()) and leaving
mContext->setSample(conditioned) as-is.
tests/fl/audio/silence_envelope.hpp (1)

19-41: Verify decay loop iteration counts.

L33 runs 31 iterations × 0.016s ≈ 0.496s (just under 1·tau = 0.5s), and L39 runs another 63 × 0.016s ≈ 1.008s for a total of ~1.504s ≈ 3·tau. At 3·tau, expected value for start=1.0, target=0 is exp(-3) ≈ 0.0498, which is right at the < 0.05 threshold — flakey margin. Consider extending by a few frames (e.g. 70 iterations → ~1.12s total additional) to get comfortably below 0.05 (target exp(-3.2) ≈ 0.041).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/fl/audio/silence_envelope.hpp` around lines 19 - 41, The decay test for
audio::SilenceEnvelope uses iteration counts that make the total silent time
hover on the flakey threshold (~exp(-3) ≈ 0.0498); update the loops that call
audio::SilenceEnvelope::update(true, 0.0f, dt) so the envelope decays
comfortably past 3*tau (for example make the first decay loop 32 iterations and
the subsequent decay loop ~70 iterations) so the final env.value() falls well
below 0.05; adjust the for loops that drive update(...) and leave the rest of
the test (Config.decayTauSeconds, initial seed via update(false,...), checks
against env.value()) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/audio_silence_gate_design.md`:
- Line 142: The sentence fragment beginning "Can be layered on top later if
demand emerges." is missing a subject; update the sentence in
docs/audio_silence_gate_design.md (the line that follows the description of the
unified volume concept) to include an explicit subject such as "This change" or
"The unified volume concept" — e.g., "This change can be layered on top later if
demand emerges." — so the sentence reads as a complete thought.
- Around line 103-104: Update the documentation to reference the correct test
filename: change the path mentioning tests/fl/audio/silence_envelope.cpp to
tests/fl/audio/silence_envelope.hpp in the `audio::SilenceEnvelope` section
(docs entry that lists src/fl/audio/silence_envelope.{h,cpp.hpp} and unity
include in src/fl/audio/_build.cpp.hpp), so the doc points to the actual unit
test file.

In `@src/fl/audio/silence_envelope.cpp.hpp`:
- Around line 24-30: The code currently treats dt <= 0.0f as an immediate snap
to target; change the conditional so only negative dt (or non-positive decay
tau) triggers an immediate snap. Specifically, in the update function that uses
mConfig.decayTauSeconds, dt, mCurrent and mConfig.targetValue, replace the check
`mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f` with a check that snaps only
when `mConfig.decayTauSeconds <= 0.0f || dt < 0.0f`, and ensure that when dt ==
0.0f the function simply returns the existing mCurrent without applying the
exponential step or modifying mCurrent.

In `@src/fl/audio/silence_envelope.h`:
- Around line 22-28: Rename the two fields in the simple struct
SilenceEnvelope::Config from decayTauSeconds and targetValue to snake_case
decay_tau_seconds and target_value everywhere (the struct definition, any
constructors/initializers, usages inside SilenceEnvelope methods, documentation
comments, tests, and any serialization/deserialization or default-value
references); update all call sites and tests to use the new names and run the
build/tests to ensure no remaining references to the old identifiers remain.

---

Nitpick comments:
In `@src/fl/audio/audio_context.cpp.hpp`:
- Around line 164-171: The clearCache routine (Context::clearCache) currently
clears FFT caches and history but does not reset the silence flag mIsSilent,
which can leave a stale true value until setSample runs; update
Context::clearCache to also set mIsSilent = false so the context is fully reset
(mirror the behavior from setSample) ensuring defensive consistency after a full
reset.

In `@src/fl/audio/audio_processor.cpp.hpp`:
- Around line 56-68: The code calls conditioned.rms() twice (once for
mNoiseFloorTracker.update and again for mContext->setSilent), which is redundant
and may yield slightly different values; compute float rms = conditioned.rms()
once after verifying conditioned.isValid() and reuse it in
mNoiseFloorTracker.update(rms) and
mContext->setSilent(!mNoiseFloorTracker.isAboveFloor(rms)), keeping the same
guard (mNoiseFloorTrackingEnabled && conditioned.isValid()) and leaving
mContext->setSample(conditioned) as-is.

In `@src/fl/audio/audio_reactive.cpp.hpp`:
- Around line 168-183: The code calls processedSample.rms() twice; compute it
once and reuse it to avoid redundant work and ensure consistency: inside the
block gated by mConfig.enableNoiseFloorTracking, call Sample::rms() once into a
local float (e.g. rms), pass that to mNoiseFloorTracker.update(rms), then later
use the same rms when calling mNoiseFloorTracker.isAboveFloor(...) to set
mContext->setSilent(...); keep the conditional checks around
mConfig.enableNoiseFloorTracking and preserve the call to
mContext->setSample(processedSample).

In `@tests/fl/audio/silence_envelope.hpp`:
- Around line 19-41: The decay test for audio::SilenceEnvelope uses iteration
counts that make the total silent time hover on the flakey threshold (~exp(-3) ≈
0.0498); update the loops that call audio::SilenceEnvelope::update(true, 0.0f,
dt) so the envelope decays comfortably past 3*tau (for example make the first
decay loop 32 iterations and the subsequent decay loop ~70 iterations) so the
final env.value() falls well below 0.05; adjust the for loops that drive
update(...) and leave the rest of the test (Config.decayTauSeconds, initial seed
via update(false,...), checks against env.value()) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 654f6483-263b-45c6-9c88-708d5cee587a

📥 Commits

Reviewing files that changed from the base of the PR and between a6e9513 and cd18a5d.

📒 Files selected for processing (11)
  • docs/audio_silence_gate_design.md
  • src/fl/audio/_build.cpp.hpp
  • src/fl/audio/audio_context.cpp.hpp
  • src/fl/audio/audio_context.h
  • src/fl/audio/audio_processor.cpp.hpp
  • src/fl/audio/audio_reactive.cpp.hpp
  • src/fl/audio/silence_envelope.cpp.hpp
  • src/fl/audio/silence_envelope.h
  • tests/fl/audio.cpp
  • tests/fl/audio/audio_context.hpp
  • tests/fl/audio/silence_envelope.hpp

Comment on lines +103 to +104
### `audio::SilenceEnvelope` (new)
See Layer 2 above. Lives in `src/fl/audio/silence_envelope.{h,cpp.hpp}`. Added to `src/fl/audio/_build.cpp.hpp` unity include. Unit test at `tests/fl/audio/silence_envelope.cpp`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the actual SilenceEnvelope test file name.
# Expect: Exactly one matching test file, then update the doc path to match it.

fd -i '^silence_envelope\.(hpp|cpp)$' tests

Repository: FastLED/FastLED

Length of output: 94


Update documentation test path from .cpp to .hpp.

Line 104 references tests/fl/audio/silence_envelope.cpp, but the actual test file is tests/fl/audio/silence_envelope.hpp. Update the documented path accordingly.

Suggested fix
-See Layer 2 above. Lives in `src/fl/audio/silence_envelope.{h,cpp.hpp}`. Added to `src/fl/audio/_build.cpp.hpp` unity include. Unit test at `tests/fl/audio/silence_envelope.cpp`.
+See Layer 2 above. Lives in `src/fl/audio/silence_envelope.{h,cpp.hpp}`. Added to `src/fl/audio/_build.cpp.hpp` unity include. Unit test at `tests/fl/audio/silence_envelope.hpp`.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### `audio::SilenceEnvelope` (new)
See Layer 2 above. Lives in `src/fl/audio/silence_envelope.{h,cpp.hpp}`. Added to `src/fl/audio/_build.cpp.hpp` unity include. Unit test at `tests/fl/audio/silence_envelope.cpp`.
### `audio::SilenceEnvelope` (new)
See Layer 2 above. Lives in `src/fl/audio/silence_envelope.{h,cpp.hpp}`. Added to `src/fl/audio/_build.cpp.hpp` unity include. Unit test at `tests/fl/audio/silence_envelope.hpp`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/audio_silence_gate_design.md` around lines 103 - 104, Update the
documentation to reference the correct test filename: change the path mentioning
tests/fl/audio/silence_envelope.cpp to tests/fl/audio/silence_envelope.hpp in
the `audio::SilenceEnvelope` section (docs entry that lists
src/fl/audio/silence_envelope.{h,cpp.hpp} and unity include in
src/fl/audio/_build.cpp.hpp), so the doc points to the actual unit test file.


## Out of scope

- Unified volume concept (`AudioLevel` struct replacing all volume getters) — considered and rejected as too churn-heavy; preserved as Option 2 in the discussion. Can be layered on top later if demand emerges.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Make this sentence complete.

Line 142 starts with “Can be layered...”; add the subject for clearer docs.

Proposed wording
-- Unified volume concept (`AudioLevel` struct replacing all volume getters) — considered and rejected as too churn-heavy; preserved as Option 2 in the discussion. Can be layered on top later if demand emerges.
+- Unified volume concept (`AudioLevel` struct replacing all volume getters) — considered and rejected as too churn-heavy; preserved as Option 2 in the discussion. It can be layered on top later if demand emerges.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Unified volume concept (`AudioLevel` struct replacing all volume getters) — considered and rejected as too churn-heavy; preserved as Option 2 in the discussion. Can be layered on top later if demand emerges.
- Unified volume concept (`AudioLevel` struct replacing all volume getters) — considered and rejected as too churn-heavy; preserved as Option 2 in the discussion. It can be layered on top later if demand emerges.
🧰 Tools
🪛 LanguageTool

[style] ~142-~142: To form a complete sentence, be sure to include a subject.
Context: ...reserved as Option 2 in the discussion. Can be layered on top later if demand emerg...

(MISSING_IT_THERE)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/audio_silence_gate_design.md` at line 142, The sentence fragment
beginning "Can be layered on top later if demand emerges." is missing a subject;
update the sentence in docs/audio_silence_gate_design.md (the line that follows
the description of the unified volume concept) to include an explicit subject
such as "This change" or "The unified volume concept" — e.g., "This change can
be layered on top later if demand emerges." — so the sentence reads as a
complete thought.

Comment on lines +24 to +30
if (mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f) {
// No decay time or zero dt → snap to target immediately.
mCurrent = mConfig.targetValue;
return mCurrent;
}
const float alpha = 1.0f - fl::expf(-dt / mConfig.decayTauSeconds);
mCurrent = mCurrent + (mConfig.targetValue - mCurrent) * alpha;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Do not snap the envelope when no time has elapsed.

Line 24 makes dt <= 0.0f jump straight to targetValue. For a first-order envelope, dt == 0 should hold the previous value; otherwise a duplicate timestamp or first-frame zero delta can hard-gate immediately instead of decaying smoothly.

Proposed fix
-    if (mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f) {
-        // No decay time or zero dt → snap to target immediately.
+    if (mConfig.decayTauSeconds <= 0.0f) {
+        // No decay time: snap to target immediately.
         mCurrent = mConfig.targetValue;
         return mCurrent;
     }
+    if (dt <= 0.0f) {
+        // No elapsed time: hold the previous envelope value.
+        return mCurrent;
+    }
     const float alpha = 1.0f - fl::expf(-dt / mConfig.decayTauSeconds);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f) {
// No decay time or zero dt → snap to target immediately.
mCurrent = mConfig.targetValue;
return mCurrent;
}
const float alpha = 1.0f - fl::expf(-dt / mConfig.decayTauSeconds);
mCurrent = mCurrent + (mConfig.targetValue - mCurrent) * alpha;
if (mConfig.decayTauSeconds <= 0.0f) {
// No decay time: snap to target immediately.
mCurrent = mConfig.targetValue;
return mCurrent;
}
if (dt <= 0.0f) {
// No elapsed time: hold the previous envelope value.
return mCurrent;
}
const float alpha = 1.0f - fl::expf(-dt / mConfig.decayTauSeconds);
mCurrent = mCurrent + (mConfig.targetValue - mCurrent) * alpha;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/audio/silence_envelope.cpp.hpp` around lines 24 - 30, The code
currently treats dt <= 0.0f as an immediate snap to target; change the
conditional so only negative dt (or non-positive decay tau) triggers an
immediate snap. Specifically, in the update function that uses
mConfig.decayTauSeconds, dt, mCurrent and mConfig.targetValue, replace the check
`mConfig.decayTauSeconds <= 0.0f || dt <= 0.0f` with a check that snaps only
when `mConfig.decayTauSeconds <= 0.0f || dt < 0.0f`, and ensure that when dt ==
0.0f the function simply returns the existing mCurrent without applying the
exponential step or modifying mCurrent.

Comment on lines +22 to +28
struct Config {
// Time constant for exponential decay toward targetValue during silence.
// After ~3*decayTauSeconds the envelope is within 5% of target.
float decayTauSeconds = 0.5f;
// Value the envelope decays toward during silence (usually 0).
float targetValue = 0.0f;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use snake_case for Config fields before this becomes public API.

SilenceEnvelope::Config is a simple struct, so decayTauSeconds and targetValue should be decay_tau_seconds and target_value; update implementation, docs, and tests accordingly. As per coding guidelines, **/*.{h,hpp}: Use mVariableName format for member variables in complex classes, lowercase snake_case for simple structs.

Proposed API rename
     struct Config {
         // Time constant for exponential decay toward targetValue during silence.
         // After ~3*decayTauSeconds the envelope is within 5% of target.
-        float decayTauSeconds = 0.5f;
+        float decay_tau_seconds = 0.5f;
         // Value the envelope decays toward during silence (usually 0).
-        float targetValue = 0.0f;
+        float target_value = 0.0f;
     };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
struct Config {
// Time constant for exponential decay toward targetValue during silence.
// After ~3*decayTauSeconds the envelope is within 5% of target.
float decayTauSeconds = 0.5f;
// Value the envelope decays toward during silence (usually 0).
float targetValue = 0.0f;
};
struct Config {
// Time constant for exponential decay toward targetValue during silence.
// After ~3*decayTauSeconds the envelope is within 5% of target.
float decay_tau_seconds = 0.5f;
// Value the envelope decays toward during silence (usually 0).
float target_value = 0.0f;
};
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fl/audio/silence_envelope.h` around lines 22 - 28, Rename the two fields
in the simple struct SilenceEnvelope::Config from decayTauSeconds and
targetValue to snake_case decay_tau_seconds and target_value everywhere (the
struct definition, any constructors/initializers, usages inside SilenceEnvelope
methods, documentation comments, tests, and any serialization/deserialization or
default-value references); update all call sites and tests to use the new names
and run the build/tests to ensure no remaining references to the old identifiers
remain.

@zackees
zackees merged commit 3288027 into master Apr 18, 2026
71 of 90 checks passed
zackees added a commit that referenced this pull request Apr 18, 2026
Adopts SilenceEnvelope for three spectral Data fields on Reactive:
dominantFrequency, magnitude, and spectralFlux. During silence the
envelope (tau=0.2s) exponentially decays each metric toward zero,
stopping the FFT noise-floor argmax from locking onto arbitrary bins
and preventing false onset detections. During audio the envelope is
strict pass-through, so existing users who have not enabled
NoiseFloorTracker see no behavior change — gating is strictly opt-in.

Tau=0.2s chosen because FFT noise is brittle and spectral metrics
should snap to zero within ~1 second of silence onset. The existing
argmax in mapFFTBinsToFrequencyChannels() is unchanged; envelopes
post-process its output inside processSample() where dt is computed
via computeAudioDt(pcm.size(), sampleRate) for frame-rate independence.

Part 3/4 of #2253 silence-gate rollout. Builds on #2306.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
Adopts SilenceEnvelope for three spectral Data fields on Reactive:
dominantFrequency, magnitude, and spectralFlux. During silence the
envelope (tau=0.2s) exponentially decays each metric toward zero,
stopping the FFT noise-floor argmax from locking onto arbitrary bins
and preventing false onset detections. During audio the envelope is
strict pass-through, so existing users who have not enabled
NoiseFloorTracker see no behavior change — gating is strictly opt-in.

Tau=0.2s chosen because FFT noise is brittle and spectral metrics
should snap to zero within ~1 second of silence onset. The existing
argmax in mapFFTBinsToFrequencyChannels() is unchanged; envelopes
post-process its output inside processSample() where dt is computed
via computeAudioDt(pcm.size(), sampleRate) for frame-rate independence.

Part 3/4 of #2253 silence-gate rollout. Builds on #2306.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
Composes a fl::audio::SilenceEnvelope (tau=2.0s, target=0) into
TempoAnalyzer so that the BPM confidence metric decays smoothly during
silence instead of persisting on stale hypotheses. The raw BPM estimate
itself is NOT gated — last-known tempo is preserved across silence so
beat sync resumes seamlessly when audio returns. Tau=2s matches the
natural persistence of musical tempo; snapping faster feels wrong.

dt is derived from context timestamp deltas so the envelope's first-order
response is frame-rate independent. When context->isSilent() is false the
envelope is a strict pass-through, preserving existing tempo-detection
behavior for users who haven't enabled NoiseFloorTracker.

Adds two integration tests: one drives 15 beats of synthetic 120 BPM
onsets and confirms confidence > 0.3, then asserts confidence < 0.05
after ~5s of silence while BPM is unchanged; the other verifies
pass-through when isSilent=false.

User-visible impact: LED effects keyed to BPM confidence (rhythmic-effect
gating) stop driving rhythm when music stops, instead of staying "in
rhythm" for 5-10+ seconds on stale onset hypotheses.

Part 4/4 of #2253 silence-gate rollout. Builds on #2306.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
Composes a fl::audio::SilenceEnvelope (tau=2.0s, target=0) into
TempoAnalyzer so that the BPM confidence metric decays smoothly during
silence instead of persisting on stale hypotheses. The raw BPM estimate
itself is NOT gated — last-known tempo is preserved across silence so
beat sync resumes seamlessly when audio returns. Tau=2s matches the
natural persistence of musical tempo; snapping faster feels wrong.

dt is derived from context timestamp deltas so the envelope's first-order
response is frame-rate independent. When context->isSilent() is false the
envelope is a strict pass-through, preserving existing tempo-detection
behavior for users who haven't enabled NoiseFloorTracker.

Adds two integration tests: one drives 15 beats of synthetic 120 BPM
onsets and confirms confidence > 0.3, then asserts confidence < 0.05
after ~5s of silence while BPM is unchanged; the other verifies
pass-through when isSilent=false.

User-visible impact: LED effects keyed to BPM confidence (rhythmic-effect
gating) stop driving rhythm when music stops, instead of staying "in
rhythm" for 5-10+ seconds on stale onset hypotheses.

Part 4/4 of #2253 silence-gate rollout. Builds on #2306.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
Vibe's MilkDrop self-normalization (imm/longAvg) drove getVol() toward
1.0 during silence (noise/noise → 1.0, plus the <0.001f clamp pinning
to 1.0). LED effects driven by getVol()/getBass()/getMid()/getTreb()
never calmed down when music stopped. Route each band's mImmRel and
mAvgRel through a SilenceEnvelope (tau=0.3s → ~1s to fully gate) so
when Context::isSilent() is true the values exponentially decay toward
0.0. Pass-through during audio preserves MilkDrop dynamics exactly.
The <0.001f startup clamp stays intact — envelope handles silence
downstream. All 8 user-visible getters now decay to near-zero in
silence: getBass, getMid, getTreb, getVol, getBassAtt, getMidAtt,
getTrebAtt, getVolAtt.

Part 2/4 of #2253 silence-gate rollout. Builds on the
Context::isSilent() + SilenceEnvelope plumbing in #2306.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Apr 18, 2026
Vibe's MilkDrop self-normalization (imm/longAvg) drove getVol() toward
1.0 during silence (noise/noise → 1.0, plus the <0.001f clamp pinning
to 1.0). LED effects driven by getVol()/getBass()/getMid()/getTreb()
never calmed down when music stopped. Route each band's mImmRel and
mAvgRel through a SilenceEnvelope (tau=0.3s → ~1s to fully gate) so
when Context::isSilent() is true the values exponentially decay toward
0.0. Pass-through during audio preserves MilkDrop dynamics exactly.
The <0.001f startup clamp stays intact — envelope handles silence
downstream. All 8 user-visible getters now decay to near-zero in
silence: getBass, getMid, getTreb, getVol, getBassAtt, getMidAtt,
getTrebAtt, getVolAtt.

Part 2/4 of #2253 silence-gate rollout. Builds on the
Context::isSilent() + SilenceEnvelope plumbing in #2306.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/audio-silence-gate branch May 30, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant