Skip to content

feat(fft): auto-detect esp_dsp, drop FL_FFT_USE_ESP_DSP opt-in (Closes #2629) - #2799

Merged
zackees merged 1 commit into
masterfrom
feat/fft-auto-detect-esp-dsp
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/fft-auto-detect-esp-dsp

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the per-sketch #define FL_FFT_USE_ESP_DSP 1 opt-in with automatic detection via FL_HAS_INCLUDE("esp_dsp.h"). ESP32 variants whose toolchain ships esp_dsp.h (esp32, esp32s3, esp32c3, esp32c6, esp32p4) get the hardware-accelerated FFT backend automatically; variants without it (esp32c2, esp32s2, esp32h2, esp32c5) and non-ESP32 targets fall through to the existing kiss_fftr scalar path. No user-visible knob.

Closes #2629.

Why

PR #2625 landed an @filter workaround on examples/AudioFftParity/AudioFftParity.ino to keep esp32c2 green after the same hard esp_dsp.h: No such file or directory failure. The @filter patched the symptom but the wrong gate was still in place — any user-authored sketch opting in for performance would hit the same wall on the same boards.

The right pattern (already used for esp_cache.h in src/platforms/esp/32/drivers/lcd_spi/) is to gate the header inclusion on FL_HAS_INCLUDE("esp_dsp.h") rather than on a user-defined macro. That makes the choice toolchain-driven instead of sketch-driven.

What changed

src/fl/audio/fft/fft_backend.h

  • Removed the #ifndef FL_FFT_USE_ESP_DSP / #define ... 0 / #endif opt-in default block.
  • Replaced #if FL_FFT_USE_ESP_DSP && defined(FL_IS_ESP32) with #if defined(FL_IS_ESP32) && FL_HAS_INCLUDE(\"esp_dsp.h\").
  • Added #include \"fl/stl/has_include.h\" (where FL_HAS_INCLUDE lives).
  • Comment block above the gate updated to describe the new auto-detect semantics.

examples/AudioFftParity/AudioFftParity.ino

  • Dropped the // @filter: ... esp32dev ... esp32s3 ... esp32c3 ... line added in PR fix(examples): restrict AudioFftParity to ESP32 boards with esp_dsp #2625.
  • Dropped the per-sketch #define FL_FFT_USE_ESP_DSP 1.
  • Doc comment updated to describe the auto-detect behavior. The existing #if !FL_FFT_ESP_DSP_AVAILABLE empty-sketch fallback already handles the no-esp_dsp ESP32 variants; no new branching needed.

Test plan

  • Diff inspected — change is two files, +37/−44 lines, purely gate-flip + comment-update + removal of opt-in opcodes. No logic shifts in the FFT dispatch itself.
  • CI's example-compile matrix is the authoritative verification: esp32dev / esp32s3 / esp32c3 / esp32c6 / esp32p4 should pick up the ESP-DSP path, and esp32c2 / esp32s2 / esp32h2 / esp32c5 should pick up the kiss_fftr / empty-sketch fallback. The same boards that previously failed without the @filter should now compile cleanly without it.
  • tests/ FFT unit tests still pass on host (scalar path was already the host default).

Notes

The agent that originally implemented this got hung up before pushing — the diff was reviewed by hand, committed inline, and pushed. The change is the minimal one the issue asks for; no incidental refactoring.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Improved FFT optimization handling by switching from manual opt-in configuration to automatic compile-time detection of ESP-DSP availability on compatible platforms.
  • Documentation

    • Updated example code and library documentation to reflect automatic ESP-DSP detection, eliminating the need for manual configuration flags.

…P_DSP opt-in (Closes #2629)

PR #2625 added an @filter to examples/AudioFftParity/AudioFftParity.ino to
keep esp32c2 (and likely esp32s2/h2/c5) green, because fft_backend.h pulled
in esp_dsp.h whenever the user set FL_FFT_USE_ESP_DSP=1 + FL_IS_ESP32 — and
that header isn't shipped by every ESP32 toolchain bundle (the low-end
RISC-V parts don't have it). The @filter fixed the symptom but the
underlying knob was wrong: any user sketch opting in for performance would
hit the same wall.

Replace the user opt-in with auto-detection via FL_HAS_INCLUDE("esp_dsp.h"),
the same pattern already used for esp_cache.h in
src/platforms/esp/32/drivers/lcd_spi/. Toolchains that ship esp_dsp.h get
the hardware backend automatically; toolchains without it fall through to
the kiss_fftr scalar path. No per-example @filter needed.

Changes:
- src/fl/audio/fft/fft_backend.h: gate flips from
  `FL_FFT_USE_ESP_DSP && defined(FL_IS_ESP32)` to
  `defined(FL_IS_ESP32) && FL_HAS_INCLUDE("esp_dsp.h")`. Removed the
  `#ifndef FL_FFT_USE_ESP_DSP / #define ... 0 / #endif` opt-in default.
- examples/AudioFftParity/AudioFftParity.ino: dropped the @filter line
  (added in #2625) and the per-sketch `#define FL_FFT_USE_ESP_DSP 1`. The
  example now compiles on every ESP32 variant — the parity test runs
  against whatever backend the auto-detect picks (ESP-DSP where present,
  empty sketch on the no-esp_dsp ESP32 variants since the existing
  `#if !FL_FFT_ESP_DSP_AVAILABLE` path already handles them).

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

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR eliminates the sketch-local opt-in pattern for ESP-DSP support by switching fft_backend.h to automatically detect esp_dsp.h availability at compile time via FL_HAS_INCLUDE(). The example sketch is simplified by removing its manual macro definition and updated to rely on the new auto-detection.

Changes

ESP-DSP auto-detection migration

Layer / File(s) Summary
Auto-detection mechanism in fft_backend.h
src/fl/audio/fft/fft_backend.h
Replace FL_FFT_USE_ESP_DSP opt-in gating with compile-time defined(FL_IS_ESP32) && FL_HAS_INCLUDE("esp_dsp.h") check that controls FL_FFT_ESP_DSP_AVAILABLE. Add fl/stl/has_include.h include and update inline documentation in the header comment and fl_fft_real_forward function to reflect auto-detection behavior.
AudioFftParity example sketch
examples/AudioFftParity/AudioFftParity.ino
Remove the sketch-local #define FL_FFT_USE_ESP_DSP 1 macro, update file header documentation to explain that ESP-DSP is now auto-detected, and adjust fallback-path comments for non-ESP32 or missing-esp_dsp.h targets.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • FastLED/FastLED#2623: Removing the sketch-local FL_FFT_USE_ESP_DSP opt-in and switching to auto-detect directly prevents toolchains without esp_dsp.h from being forced to include it unnecessarily.
  • FastLED/FastLED#2629: Both changes migrate from sketch-local opt-in (FL_FFT_USE_ESP_DSP) to compile-time auto-detection via FL_HAS_INCLUDE("esp_dsp.h") in the same files.
  • FastLED/FastLED#2308: The auto-detection mechanism enables the ESP-DSP backend optimization pathway that the performance issue proposes using to accelerate FFT operations.

Possibly related PRs

  • FastLED/FastLED#2315: Directly related—both PRs modify ESP-DSP selection in AudioFftParity.ino and src/fl/audio/fft/fft_backend.h, with this PR switching from the prior PR's sketch opt-in macro to automatic toolchain detection.
  • FastLED/FastLED#2310: Both PRs touch src/fl/audio/fft/fft_backend.h's ESP-DSP integration—refactor(audio/fft): dispatcher for ESP-DSP FFT backend #2310 introduces FL_FFT_USE_ESP_DSP gating, and this PR replaces it with compile-time auto-detection.
  • FastLED/FastLED#2625: Both address AudioFftParity build failures on boards without esp_dsp.h, but with different approaches: this PR auto-detects availability, while #2625 filters the example to ESP32 boards only.

Poem

🐰 From opt-in whispers to auto-detect cheer,
A macro escapes, its purpose runs clear,
The toolchain now speaks—"I have this, I do!"—
No forcing the builds that shouldn't come through,
The ESP flies fast when the chips truly bear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 clearly summarizes the primary change: replacing manual opt-in with automatic ESP-DSP detection and removing the old macro.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/fft-auto-detect-esp-dsp

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/fl/audio/fft/fft_backend.h (1)

98-108: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Use defined/undefined pattern for capability macros per coding guidelines.

The capability flags FL_FFT_ESP_DSP_AVAILABLE and FL_FFT_ESP_DSP_ACTIVE should follow the Type 3 pattern from agents/docs/cpp-standards.md: defined/undefined with no values, not 0/1. Code consuming them should use #ifdef/#if defined() checks.

As per coding guidelines: "For feature availability/capability gates (Type 3), ensure boolean capability flags are also 'defined/undefined' (no values). Code that consumes them should use #ifdef/#if defined style checks so unsupported platforms evaluate false cleanly."

✅ Proposed fix to match the defined/undefined pattern
 `#if` defined(FL_IS_ESP32) && FL_HAS_INCLUDE("esp_dsp.h")
-#define FL_FFT_ESP_DSP_AVAILABLE 1
+#define FL_FFT_ESP_DSP_AVAILABLE
 `#include` "esp_dsp.h"
 `#include` "fl/stl/vector.h"
 `#include` "fl/log/log.h"
 `#include` "fl/math/math.h"  // cosf / sinf wrappers
-#else
-#define FL_FFT_ESP_DSP_AVAILABLE 0
 `#endif`
 
-#define FL_FFT_ESP_DSP_ACTIVE FL_FFT_ESP_DSP_AVAILABLE
+#ifdef FL_FFT_ESP_DSP_AVAILABLE
+#define FL_FFT_ESP_DSP_ACTIVE
+#endif

This would also require updating line 114 to use #ifdef FL_FFT_ESP_DSP_AVAILABLE and line 31 in AudioFftParity.ino to use #ifndef FL_FFT_ESP_DSP_AVAILABLE.

🤖 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 `@src/fl/audio/fft/fft_backend.h` around lines 98 - 108, Replace the 0/1
capability macros with a defined/undefined pattern: when esp_dsp is present, use
plain `#define` FL_FFT_ESP_DSP_AVAILABLE (no value) and then `#define`
FL_FFT_ESP_DSP_ACTIVE (no value) after including headers; when not present,
ensure those symbols are not defined (use `#undef` or omit defines). Update any
consumers of these flags (places checking FL_FFT_ESP_DSP_AVAILABLE or
FL_FFT_ESP_DSP_ACTIVE) to use `#ifdef` or `#if` defined(FL_FFT_ESP_DSP_AVAILABLE)
style checks rather than comparing to 0/1 so the feature gate evaluates
correctly on unsupported platforms.
🤖 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.

Outside diff comments:
In `@src/fl/audio/fft/fft_backend.h`:
- Around line 98-108: Replace the 0/1 capability macros with a defined/undefined
pattern: when esp_dsp is present, use plain `#define` FL_FFT_ESP_DSP_AVAILABLE (no
value) and then `#define` FL_FFT_ESP_DSP_ACTIVE (no value) after including
headers; when not present, ensure those symbols are not defined (use `#undef` or
omit defines). Update any consumers of these flags (places checking
FL_FFT_ESP_DSP_AVAILABLE or FL_FFT_ESP_DSP_ACTIVE) to use `#ifdef` or `#if`
defined(FL_FFT_ESP_DSP_AVAILABLE) style checks rather than comparing to 0/1 so
the feature gate evaluates correctly on unsupported platforms.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de586ea5-cb8c-4d2d-a997-d831eeb75edc

📥 Commits

Reviewing files that changed from the base of the PR and between 787de45 and 998ccfe.

📒 Files selected for processing (2)
  • examples/AudioFftParity/AudioFftParity.ino
  • src/fl/audio/fft/fft_backend.h

@zackees
zackees merged commit 350a389 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
@zackees
zackees deleted the feat/fft-auto-detect-esp-dsp 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.

fl::audio::fft: eliminate FL_FFT_USE_ESP_DSP opt-in, auto-detect via FL_HAS_INCLUDE + scalar fallback

1 participant