Repository navigation
Description
Summary
Follow-up to #2254 Issue 3 ("FastLED Audio driver reduces FPS 100 → 60"). The streaming/yield fixes in commit 25873cf32c and PR #2300 did NOT resolve this — those targeted I2S and SPI drivers. Audio is a separate code path and its bottleneck is processing time per call, not scheduler starvation.
From profiling (baseline 16 kHz, 1000 iterations, cached from earlier work):
| Stage | Time/call | Notes |
|---|---|---|
| EnergyAnalyzer (baseline) | 17.6 µs | Minimum overhead |
| FrequencyBands | 72 µs | = 54 µs FFT + 18 µs analysis |
| VibeDetector | 69 µs | = 54 µs FFT + 15 µs analysis |
| VocalDetector | 51 µs | FFT user |
| BeatDetector | 25 µs | No FFT |
| TempoAnalyzer | 23 µs | No FFT |
| TransientDetector | 24 µs | No FFT |
| PitchDetector | 19 µs | Clever FFT reuse |
| All detectors combined | ~165 µs | FFT is shared once (~54 µs), analyses stack |
The shared FFT path through src/fl/audio/fft/fft_impl.cpp.hpp uses kiss_fftr (third_party/cq_kernel), a portable pure-C FFT. On Xtensa / RISC-V it doesn't use SIMD / DSP acceleration.
Two complementary optimizations
(A) Replace FFT backend with ESP-DSP on ESP32 — IN PROGRESS
ESP-DSP is already bundled with the Arduino ESP32 framework (verified at framework-arduinoespressif32-libs/esp32*/include/espressif__esp-dsp/modules/fft/). It provides dsps_fft2r/dsps_fft4r with hardware-optimized radix-2/radix-4 using Xtensa DSP instructions on ESP32/S2/S3 and RISC-V DSP extensions on C3/C6. Typical 3-5× speedup on Xtensa, 2-3× on RISC-V → expected FFT cost drop from ~54 µs to ~10-20 µs. Detectors stacking FFT get ~35 µs back per frame.
Scope: add a platform-gated FFT backend in src/fl/audio/fft/. Conditional on ESP_PLATFORM or similar; kiss_fftr stays the universal fallback. Does NOT change the public FFT API.
(B) Audio task on separate core (ESP32 multi-core only) — QUEUED
Pin audio processing to the idle second core on ESP32 variants that have one, so audio never competes with LED render for CPU.
Key research findings:
- ESP32 FastLED coroutine layer already has
CoroutineConfig::core_id(src/fl/task/task.h:135) — but it's currently ignored in the ESP32 backend (src/platforms/esp/32/coroutine_esp32.impl.hpp:202-210hardcodestskNO_AFFINITY). - Dual-core platforms where this actually helps: ESP32 (original), ESP32-S3, ESP32-P4. Everything else is effectively single-core from an RTOS-task perspective.
- Single-core ESP32 variants (S2, C2, C3, C5, C6, H2):
xTaskCreatePinnedToCore(core=1)returns NULL. Must validate before calling. - Non-ESP32 platforms with multiple cores don't map to this model:
- RP2040/RP2350 (dual Cortex-M0+ / M33) — no SMP RTOS; uses
multicore_launch_core1()bare-metal. - STM32 H747 (M7+M4) — asymmetric multiprocessing, partitioned firmware, no task affinity.
- Teensy 4.x — single-core; FreeRTOS optional but no SMP.
- RP2040/RP2350 (dual Cortex-M0+ / M33) — no SMP RTOS; uses
Proposed feature-flag additions (matches existing feature_flags/ convention):
// src/platforms/esp/32/feature_flags/enabled.h
#if defined(FL_IS_ESP_32DEV) || defined(FL_IS_ESP_32S3) || defined(FL_IS_ESP_32P4)
#define FL_HAS_MULTICORE_AFFINITY 1
#define FL_CPU_CORES 2
#else
#define FL_HAS_MULTICORE_AFFINITY 0
#define FL_CPU_CORES 1
#endifDefault behavior: status quo — audio runs on whatever core the OS schedules it on. Only opt-in consumers get the pinning benefit. Matches user direction: "(1) should be gated by a setting, default is status quo".
Implementation sketch for (B):
- Wire
CoroutineConfig::core_idthroughcreateTaskCoroutine()incoroutine_esp32.impl.hpp— respect the value, validate againstFL_CPU_CORES, fall back totskNO_AFFINITYif out of range. - Add
fl::audio::Processor::setCoreAffinity(int core)API surface — stores the core ID and passes it totask::every_ms(1)when constructing the auto-update coroutine. - Document: "call
setCoreAffinity(1)on ESP32/S3/P4 before.start()to offload audio onto the idle core".
Test plan
For (A):
- Host unit test (
bash test) — kiss_fftr path unchanged, regression-free. - ESP32-S3 hardware — measure FFT cost before/after with the same 1000-iteration benchmark. Expected: 54 µs → ~15 µs.
- Validate FFT output matches kiss_fftr within rounding tolerance (test harness in tests/fl/audio/fft/).
For (B):
- Host unit test —
CoroutineConfig::core_idhonored by a mock backend, out-of-range rejected. - ESP32-S3 hardware — verify audio task pinned to core 1 (read
uxTaskGetCoreIDat runtime), confirm LED FPS under audio + FastLED.show recovers to ~100 FPS. - ESP32-C3 single-core — confirm out-of-range core_id gracefully falls back.
Related
- ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 — parent issue (Issue 3 is this tracker's reason to exist).
- feat: fix #2254 SPI long-strip bug + enable RMT RX DMA streaming #2300 — merged SPI+RMT streaming fix (unrelated to audio, but proved the yield-path fix addressed I2S).
25873cf32c— deep-yield fix that resolved ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 Issue 1 (I2S websocket starvation).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(audio/fft): add fft_backend.h dispatcher for future ESP-DSP path
docs(audio/fft): document hardware-FFT survey in backend dispatcher
refactor(audio/fft): dispatcher for ESP-DSP FFT backend (#2310)
feat(audio/fft): implement ESP-DSP real-FFT backend (opt-in)
feat(audio/fft): ESP-DSP backend implementation + AudioFftParity test
feat(audio/fft): ESP-DSP backend implementation + AudioFftParity test (…
feat(esp32): honor CoroutineConfig::core_id for task affinity
feat(esp32): honor CoroutineConfig::core_id for task affinity (#2337)
feat(audio,task): Worker primitive + Processor::setCoreAffinity offload
zackees commentedon Jun 5, 2026
Closing — the two proposals in this issue landed or were intentionally parked:
refactor(audio/fft): dispatcher for ESP-DSP FFT backend) + feat(audio/fft): ESP-DSP backend + AudioFftParity hardware validation harness #2315 (feat(audio/fft): ESP-DSP backend + AudioFftParity hardware validation harness). Auto-detect just landed in feat(fft): auto-detect esp_dsp, drop FL_FFT_USE_ESP_DSP opt-in (Closes #2629) #2799 (feat(fft): auto-detect esp_dsp via FL_HAS_INCLUDE, drop FL_FFT_USE_ESP_DSP opt-in) — no user knob needed any more.research: audio core affinity offload — parked after prototype, lessons learned). research: audio core affinity offload — parked after prototype, lessons learned #2359 is the canonical re-open trigger if a measured FPS gap appears after Option A is widely in use.Closing because the actionable scope is delivered. Re-open with measured before/after FPS numbers if Option A turns out to be insufficient on a specific board — that's the signal #2359 is waiting for.