Repository navigation
feat(examples/animartrix): 3-state audio orchestrator with hysteresis (Closes #2713) - #2809
Conversation
…Closes #2713) Replaces the existing "bass -> time-warp speed" reactivity in AnimartrixRing with a top-level SoundOrchestrator that classifies the live audio stream into one of three states and picks a different Animartrix visual family per state: * Silence -> SLOW_FADE / WATER / PARAMETRIC_WATER / FLUFFY_BLOBS (low engine speed, no time warp, restrained motion) * Disorganized -> RGB_BLOBS5 / WAVES / POLAR_WAVES / COMPLEX_KALEIDO (vibe.bass nudges engine speed within a bounded span -- time warp survives as a *secondary* effect, no longer the primary audio interaction) * BpmLocked -> RINGS / CHASING_SPIRALS / SPIRALUS / CENTER_FIELD (kick/snare/downbeat events ease-out pulse the engine speed, BPM sets a gentle baseline scale around 120 BPM, measurePhase contributes a sine bow between beats) Classifier consumes only existing fl::audio::Processor primitives: isSilent(), getTempoConfidence(), getBeatConfidence(), getBPM(), getVibeBass(), getMeasurePhase(), and event callbacks onKick / onSnare / onDownbeat. No new audio infrastructure was added under src/fl/audio/. Hysteresis is layered: 1. Asymmetric silence timers (slow-enter 700ms, fast-exit 150ms) so a short audio gap does not drop us into ambient mid-song, but a real silence does land us in the Silence bank quickly enough. 2. A candidate state must hold continuously for classifierHysteresisMs (default 400ms) before being accepted. 3. The current state must have served minDwellMs (default 1500ms) before any transition is honored. UI sliders expose both knobs. Animartrix bank cycling: within a state we slowly rotate through the state's visual bank (~18s period) so a long-held state still has variety. Visual tuning numbers (pulse decay, BPM normalization, speed spans) are deliberately conservative; they are documented constants intended to be refined on hardware against real music in a follow-up.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a 3-state SoundOrchestrator (Silence, Disorganized, BpmLocked), implements classification, per-state animation banks and speed drivers, and wires the orchestrator into AnimartrixRing with UI controls and manual-audio-pump fallback. ChangesAnimartrixRing 3-State Sound Orchestrator
Sequence Diagram(s)sequenceDiagram
participant Processor as Audio Processor
participant Orchestrator as SoundOrchestrator
participant AnimartrixA as Animartrix
participant Engine as FxEngine
Processor->>Orchestrator: audio callbacks (kick/snare/downbeat)
Orchestrator->>Orchestrator: classify(nowMs)
alt state change
Orchestrator->>AnimartrixA: switchAnimationIfNeeded()
AnimartrixA->>Orchestrator: animation applied
end
Orchestrator->>Engine: setSpeed(computedSpeed)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)examples/AnimartrixRing/sound_orchestrator.cppIn file included from examples/AnimartrixRing/sound_orchestrator.cpp:2: ... [truncated 1178 characters] ... clude" 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
examples/AnimartrixRing/AnimartrixRing.ino (1)
120-129:⚠️ Potential issue | 🟠 Major | ⚡ Quick winOnly enable auto-pump after
FastLED.add(input)succeeds.If
audio.audioInput()is present butFastLED.add(input)returns no processor,gAutoPumpstill staystrue, and Line 148 then skips the manualgAudioProcessor->update(sample)path forever. The fallback processor created on Lines 126-129 never receives samples, so the orchestrator cannot classify audio on the exact platforms this branch is meant to support.Suggested fix
auto input = audio.audioInput(); if (input) { gAudioProcessor = FastLED.add(input); - gAutoPump = true; - printf("AnimartrixRing: Audio routed via FastLED.add() (auto-pump)\n"); + gAutoPump = static_cast<bool>(gAudioProcessor); + if (gAutoPump) { + printf("AnimartrixRing: Audio routed via FastLED.add() (auto-pump)\n"); + } } if (!gAudioProcessor) { gAudioProcessor = fl::make_shared<fl::audio::Processor>(); + gAutoPump = false; printf("AnimartrixRing: Audio using manual pump (fallback)\n"); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AnimartrixRing/AnimartrixRing.ino` around lines 120 - 129, The code sets gAutoPump = true immediately after calling FastLED.add(input) without checking if that call returned a valid processor, which can leave auto-pump enabled even when gAudioProcessor is null; change the logic so you only set gAutoPump (and log the auto-pump message) after verifying FastLED.add(input) returned a non-null gAudioProcessor (i.e., check the result of FastLED.add(input) before assigning gAutoPump and printing), and only fall back to creating gAudioProcessor via fl::make_shared<fl::audio::Processor>() when gAudioProcessor is still null so the manual pump path receives samples.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/AnimartrixRing/sound_orchestrator.cpp`:
- Around line 109-137: The code updates mNonSilentSinceMs but never uses it,
allowing a single non-silent frame to exit SoundState::Silence immediately;
update the instant-state logic to require the configured silenceExitMs before
leaving Silence: when !isSilent and mState == SoundState::Silence, only consider
leaving Silence (to Disorganized or BpmLocked) if mNonSilentSinceMs != 0 and
(nowMs - mNonSilentSinceMs) >= mCfg.silenceExitMs; ensure mNonSilentSinceMs is
set when the first non-silent frame is seen (it already is) and reset
appropriately when re-entering Silence, and keep existing bpm/tempo threshold
checks (tempoConf/beatConf and mCfg.tempoConfidenceEnter/exit) for transitions
to BpmLocked.
---
Outside diff comments:
In `@examples/AnimartrixRing/AnimartrixRing.ino`:
- Around line 120-129: The code sets gAutoPump = true immediately after calling
FastLED.add(input) without checking if that call returned a valid processor,
which can leave auto-pump enabled even when gAudioProcessor is null; change the
logic so you only set gAutoPump (and log the auto-pump message) after verifying
FastLED.add(input) returned a non-null gAudioProcessor (i.e., check the result
of FastLED.add(input) before assigning gAutoPump and printing), and only fall
back to creating gAudioProcessor via fl::make_shared<fl::audio::Processor>()
when gAudioProcessor is still null so the manual pump path receives samples.
🪄 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: a0d80920-e80a-4955-89a6-aa7c4824bf1f
📒 Files selected for processing (3)
examples/AnimartrixRing/AnimartrixRing.inoexamples/AnimartrixRing/sound_orchestrator.cppexamples/AnimartrixRing/sound_orchestrator.h
Two valid CodeRabbit findings on the 3-state orchestrator branch: 1. sound_orchestrator.cpp: actually use mNonSilentSinceMs. Previously the timer was tracked but never consulted, so a single non-silent frame would immediately drop Silence -> Disorganized and bypass the asymmetric silenceExitMs hysteresis advertised on OrchestratorConfig. Added a silenceReleased gate that holds Silence until silenceExitMs of contiguous non-silent audio has elapsed. 2. AnimartrixRing.ino: only enable gAutoPump when FastLED.add(input) actually returned a live processor. Previously gAutoPump was set true unconditionally; if FastLED.add() returned null, the fallback make_shared<Processor>() was used but the manual-pump path in loop() was skipped forever, so the orchestrator never saw any samples on platforms without a backing audio device. No design changes: still sketch-only, still 3 states, still 3 layers of hysteresis, no src/fl/audio/ touches. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Re: CodeRabbit review #4435841438 Both findings fixed in 58a0cf1:
WASM compile ( |
AnimartrixRing had grown two jobs: demonstrating how to sample a ring out of a 2D Animartrix grid, and hosting the audio-reactive orchestration work from FastLED#2713/FastLED#2809. Those want opposite things -- the technique demo wants to be minimal, the product sketch wants to grow. AnimartrixRing is now the technique demo only: - all audio removed (UIAudio, Processor, orchestrator, Teensy <Audio.h>) - uses the existing makeRingScreenMap() helper instead of an inline lambda - adds a UIDropdown animation selector (order matches AnimartrixAnim, so the index feeds fxSet() directly, same convention as Animartrix.ino) - deletes audio_reactive.{h,cpp}, dead since FastLED#2809 superseded it MoodRing is the new product sketch: - sound_orchestrator.{h,cpp} moved here, namespace animartrix_ring -> mood_ring - orchestrator defaults to enabled; a room-sensing toy that boots deaf is not the product - README carries the FastLED#2256 architecture and the remaining roadmap (control bus, overlay compositor, mood bias, NoiseRing, patch schema) This restructures the split described in FastLED#2256 section 9, which had AnimartrixRing staying unchanged as legacy: per maintainer direction the audio leaves AnimartrixRing entirely rather than being duplicated. Refs FastLED#2256 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Summary
Replaces the existing bass -> time-warp speed reactivity in
examples/AnimartrixRing/AnimartrixRing.inowith a top-levelSoundOrchestratorthat classifies the live audio stream into one of three states and picks a different Animartrix visual family per state. Closes #2713.SilenceSLOW_FADE,WATER,PARAMETRIC_WATER,FLUFFY_BLOBSDisorganizedRGB_BLOBS5,WAVES,POLAR_WAVES,COMPLEX_KALEIDOvibe.bassnudges engine speed within a bounded span -- time warp survives as a secondary effect, no longer the primary audio interactionBpmLockedRINGS,CHASING_SPIRALS,SPIRALUS,CENTER_FIELDkick/snare/downbeatevents ease-out pulse the engine speed;BPMsets a gentle baseline scale around 120 BPM;measurePhasecontributes a sine bow between beatsThe orchestrator consumes only existing
fl::audio::Processorprimitives:isSilent(),getTempoConfidence(),getBeatConfidence(),getBPM(),getVibeBass(),getMeasurePhase(),onKick,onSnare,onDownbeat. No new audio infrastructure was added undersrc/fl/audio/.Hysteresis
Three layers, all sketch-scoped (UI sliders expose the dwell + hysteresis knobs):
classifierHysteresisMs(default 400ms) before being accepted.minDwellMs(default 1500ms) before any transition is honored.What's deferred
Visual tuning numbers (pulse decay, BPM normalization, speed spans) are deliberately conservative and live as documented constants in
sound_orchestrator.cpp. They are intended to be refined on hardware against real music in a follow-up; I don't have a ring + audio rig here to dial them in against actual songs.Files
examples/AnimartrixRing/sound_orchestrator.h(new) -- public API +OrchestratorConfigexamples/AnimartrixRing/sound_orchestrator.cpp(new) -- classifier + per-state drivers + visual-bank cyclingexamples/AnimartrixRing/AnimartrixRing.ino-- now constructs and ticks the orchestrator instead of wiringonVibeLevelsdirectly tofxEngine.setSpeed()Test plan
bash lint(Python, C++, JS, meson) -- passes cleanbash compile wasm --examples AnimartrixRing-- passes (78s)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor