Skip to content

feat(examples/animartrix): 3-state audio orchestrator with hysteresis (Closes #2713) - #2809

Merged
zackees merged 2 commits into
masterfrom
feat/2713-animartrix-orchestrator
Jun 5, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/2713-animartrix-orchestrator

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the existing bass -> time-warp speed reactivity in examples/AnimartrixRing/AnimartrixRing.ino 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. Closes #2713.

State Visual bank Audio -> visual mapping
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

The orchestrator consumes only existing fl::audio::Processor primitives: isSilent(), getTempoConfidence(), getBeatConfidence(), getBPM(), getVibeBass(), getMeasurePhase(), onKick, onSnare, onDownbeat. No new audio infrastructure was added under src/fl/audio/.

Hysteresis

Three layers, all sketch-scoped (UI sliders expose the dwell + hysteresis knobs):

  1. Asymmetric silence timers -- slow-enter (700ms) / fast-exit (150ms). A brief audio gap does not drop us into ambient mid-song, but real silence does land us in the Silence bank quickly enough.
  2. Candidate-state hold -- a candidate state must hold continuously for classifierHysteresisMs (default 400ms) before being accepted.
  3. Minimum dwell -- the current state must have served 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 + OrchestratorConfig
  • examples/AnimartrixRing/sound_orchestrator.cpp (new) -- classifier + per-state drivers + visual-bank cycling
  • examples/AnimartrixRing/AnimartrixRing.ino -- now constructs and ticks the orchestrator instead of wiring onVibeLevels directly to fxEngine.setSpeed()

Test plan

  • bash lint (Python, C++, JS, meson) -- passes clean
  • bash compile wasm --examples AnimartrixRing -- passes (78s)
  • Hardware visual validation on a 244-LED ring against silence / pink noise / a metronome / a real track -- this is the follow-up tuning pass referenced above
  • CI matrix (ESP32 family, Teensy, AVR via the existing example-compile workflows)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added audio orchestration for AnimartrixRing with three synchronized states (Silence, Disorganized, BpmLocked).
    • Added UI controls to enable the orchestrator and tune dwell/hysteresis behavior; logs orchestrator state transitions and engine speed.
  • Refactor

    • Replaced prior reactive Vibe-based UI/callbacks with the new state-driven orchestrator and updated per-frame audio handling (includes manual-pump fallback).

…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.
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4818d9cd-bc9f-41bc-91f2-6a31c01fcf39

📥 Commits

Reviewing files that changed from the base of the PR and between 024371b and 58a0cf1.

📒 Files selected for processing (2)
  • examples/AnimartrixRing/AnimartrixRing.ino
  • examples/AnimartrixRing/sound_orchestrator.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/AnimartrixRing/sound_orchestrator.cpp
  • examples/AnimartrixRing/AnimartrixRing.ino

📝 Walkthrough

Walkthrough

Adds 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.

Changes

AnimartrixRing 3-State Sound Orchestrator

Layer / File(s) Summary
Orchestrator contract & configuration
examples/AnimartrixRing/sound_orchestrator.h
SoundState enum, toString, OrchestratorConfig with thresholds/dwell/hysteresis and state params; SoundOrchestrator API: ctor, begin(), tick(), accessors, and config setters.
Orchestrator core implementation
examples/AnimartrixRing/sound_orchestrator.cpp
Defines toString, per-state animation banks, ctor and begin() (processor callbacks), pickAnimationFor()/switchAnimationIfNeeded(), classify() with hysteresis/dwell, driveSilence/driveDisorganized/driveBpmLocked, and tick() that updates state and calls mEngine->setSpeed.
Sketch integration & UI
examples/AnimartrixRing/AnimartrixRing.ino
Revised header, added sound_orchestrator.h include, replaced Vibe UI with orchestrator enable/dwell/hysteresis controls, constructs and begins gOrchestrator, supports FastLED.auto-pump or manual audio pumping, per-frame config overrides, orchestrator ticking, and state/speed logging.

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)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

  • #2256: Matches — implements the requested 3-state orchestrator and replaces time-warp-only audio response in AnimartrixRing.

Poem

🐇 I listen close and sort the sound,
From hush to chaos, then beats profound.
I pick the lights, I set the pace,
A ring that dances to the bass.
Hop, twirl, blink — the orchestra found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: introducing a 3-state audio orchestrator with hysteresis for AnimartrixRing, replacing the previous bass-only time-warp approach.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #2713: 3-state classification (Silence/Disorganized/BpmLocked), distinct animation selection per state, audio signal mapping (silence/energy/beat/spectrum), hysteresis with dwell times, and uses only existing Processor APIs.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the orchestrator and integrating it into AnimartrixRing.ino; no additions to src/fl/audio/ infrastructure or unrelated modifications are present.

✏️ 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/2713-animartrix-orchestrator

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.cpp

In file included from examples/AnimartrixRing/sound_orchestrator.cpp:2:
examples/AnimartrixRing/sound_orchestrator.h:22:10: fatal error: 'FastLED.h' file not found
22 | #include "FastLED.h"
| ^~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/58a0cf139932da768485c7a5603d9dcaf904d27a-7abddb2abef46912/tmp/clang_command_.tmp.013f4b.txt
++Contents of '/tmp/coderabbit-infer/58a0cf139932da768485c7a5603d9dcaf904d27a-7abddb2abef46912/tmp/clang_command_.tmp.013f4b.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-plugin-arg-BiniouASTExporter" "MAX_STRING_SIZE=65535" "-cc1" "-

... [truncated 1178 characters] ...

clude"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1"
"-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/7abddb2abef46912/file.o" "-x" "c++"
"examples/AnimartrixRing/sound_orchestrator.cpp" "-O0" "-fno-builtin"
"-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


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.

@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: 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 win

Only enable auto-pump after FastLED.add(input) succeeds.

If audio.audioInput() is present but FastLED.add(input) returns no processor, gAutoPump still stays true, and Line 148 then skips the manual gAudioProcessor->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

📥 Commits

Reviewing files that changed from the base of the PR and between 787de45 and 024371b.

📒 Files selected for processing (3)
  • examples/AnimartrixRing/AnimartrixRing.ino
  • examples/AnimartrixRing/sound_orchestrator.cpp
  • examples/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]>
@zackees

zackees commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

Re: CodeRabbit review #4435841438

Both findings fixed in 58a0cf1:

  • Inline (sound_orchestrator.cpp L109-137): silenceExitMs not applied — fixed via new silenceReleased gate; reply posted inline on the original thread.
  • Outside-diff (AnimartrixRing.ino L120-129): gAutoPump enabled even when FastLED.add(input) returns null — fixed. gAutoPump is now only set true when FastLED.add(input) actually returns a non-null processor. The fallback branch explicitly sets gAutoPump = false so the manual-pump path in loop() runs and the orchestrator receives samples on platforms where FastLED.add() doesn't take.

WASM compile (bash compile wasm --examples AnimartrixRing) passes; bash lint clean. No design changes (still sketch-only, 3 states, 3-layer hysteresis, no src/fl/audio/ touches).

@zackees
zackees merged commit cf8d543 into master Jun 5, 2026
9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
pull Bot pushed a commit to manmuqingshan/FastLED that referenced this pull request Aug 18, 2026
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]>
@zackees
zackees deleted the feat/2713-animartrix-orchestrator branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

AnimartrixRing: replace time-warp-only audio response with a 3-state sound orchestrator

1 participant