Repository navigation
feat(audio): Reactive spectral metrics gate in silence (#2253) - #2309
Conversation
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]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe changes add silence-gating functionality to the audio reactive system by introducing three Changes
Sequence DiagramsequenceDiagram
participant Sample as Audio Sample
participant Reactive as Reactive
participant Spectral as Spectral Analysis
participant Context as Context
participant Envelope as SilenceEnvelope
Sample->>Reactive: processSample(pcm_buffer)
Reactive->>Spectral: updateSpectralFlux()
Spectral->>Reactive: returns dominantFreq, magnitude, flux
Reactive->>Context: isSilent()
Context-->>Reactive: boolean (silent status)
alt Silence Detected
Reactive->>Envelope: update(silent=true, currentValue, dt)
Envelope->>Envelope: exponential decay
Envelope-->>Reactive: decayed_value
Reactive->>Reactive: mCurrentData.dominantFrequency = decayed_value
Reactive->>Reactive: mCurrentData.magnitude = decayed_value
Reactive->>Reactive: mCurrentData.spectralFlux = decayed_value
else Audio Present
Envelope->>Envelope: update(silent=false, currentValue, dt)
Envelope-->>Reactive: pass-through currentValue
Reactive->>Reactive: mCurrentData.* = currentValue
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
📊 Header Compilation PerformanceTotal Time: 1005.10ms Top 5 Slowest Headers
Warnings
Full Report |
…oor (#2253) NoiseFloorTracker.update() initializes its floor to the first observed level on the first sample. For a steady loud signal, that makes isAboveFloor() stuck at false — floor catches up to level, so level > floor+hysteresisMargin never holds. Reactive (PR #2309) and Processor wired setSilent() to !isAboveFloor(), which caused a LOUD 1 kHz tone to be flagged as silent, then decayed dominantFrequency and magnitude to zero via SilenceEnvelope. Fix: gate silence on an absolute RMS threshold (10.0, matching NoiseFloorTrackerConfig::minFloor default). The noise-floor estimate is still tracked for detector internals but is no longer the silence primitive. "No signal present" is an absolute-level concept. Tests: - audio_reactive.cpp: extend phase 2 silence to 3s (~15 taus) so pure-exponential decay reaches the < 0.01 assertion instead of depending on the now-fixed buggy silent-during-loud shortcut. - tempo_analyzer.hpp: extend phase 2 silence to 8s (tau=2s → 4 taus) so exp(-4) ≈ 0.018 decay is well under 0.05 even when liveConfidence comes in high; prior 5s was flaky at the threshold. Also fix pre-existing KBI003 lint in ci/util/fbuild_compiledb.py that was blocking this branch's lint gate. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…oor (#2253) (#2322) NoiseFloorTracker.update() initializes its floor to the first observed level on the first sample. For a steady loud signal, that makes isAboveFloor() stuck at false — floor catches up to level, so level > floor+hysteresisMargin never holds. Reactive (PR #2309) and Processor wired setSilent() to !isAboveFloor(), which caused a LOUD 1 kHz tone to be flagged as silent, then decayed dominantFrequency and magnitude to zero via SilenceEnvelope. Fix: gate silence on an absolute RMS threshold (10.0, matching NoiseFloorTrackerConfig::minFloor default). The noise-floor estimate is still tracked for detector internals but is no longer the silence primitive. "No signal present" is an absolute-level concept. Tests: - audio_reactive.cpp: extend phase 2 silence to 3s (~15 taus) so pure-exponential decay reaches the < 0.01 assertion instead of depending on the now-fixed buggy silent-during-loud shortcut. - tempo_analyzer.hpp: extend phase 2 silence to 8s (tau=2s → 4 taus) so exp(-4) ≈ 0.018 decay is well under 0.05 even when liveConfidence comes in high; prior 5s was flaky at the threshold. Also fix pre-existing KBI003 lint in ci/util/fbuild_compiledb.py that was blocking this branch's lint gate. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Part 3/4 of the #2253 silence-gate rollout. Gates three spectral
Datafields onfl::audio::ReactivethroughSilenceEnvelopeso they decay to zero when the pipeline signals silence.Data::dominantFrequency— previously the FFT argmax latched onto arbitrary bins during silence (numerical noise floor).Data::magnitude— companion todominantFrequency; same issue.Data::spectralFlux— could fire false onsets on noise-floor flicker.All three now pass through
SilenceEnvelope(tau=0.2s) insideprocessSample(). During audio (Context::isSilent() == false) the envelope is a strict pass-through; during silence it exponentially decays toward zero. Frame-rate-independentdtcomes fromcomputeAudioDt(pcm.size(), sampleRate). No behavior change for users who haven't opted intoenableNoiseFloorTracking.Tau=0.2s per the design-doc recommendation: spectral metrics are brittle and should snap to zero within ~1 s of silence onset. The existing argmax in
mapFFTBinsToFrequencyChannels()is untouched — envelopes post-process its output.Builds on #2306 (Phase 1:
Context::isSilent()+SilenceEnvelope). Out-of-scope for this PR:Vibe(PR-C, parallel) andTempoAnalyzer(PR-E, next).Test plan
audio::Reactive - spectral metrics decay to zero on silence (FastLED#2253)— drives 1 s of 440 Hz sine, then 1 s of zero-PCM, asserts all three fields < 0.01 after silence.audio::Reactive - spectral metrics are pass-through during loud audio (FastLED#2253)— confirms unchanged behavior during live audio (dominant frequency in audible range, magnitude > 0).bash test fl_audio --debugpasses (ASAN/LSAN/UBSAN clean).bash lintclean on all three touched files.fl_audiotests continue to pass (no behavior change when NFT not enabled).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests