Repository navigation
feat(fft): auto-detect esp_dsp, drop FL_FFT_USE_ESP_DSP opt-in (Closes #2629) - #2799
Conversation
…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]>
📝 WalkthroughWalkthroughThe PR eliminates the sketch-local opt-in pattern for ESP-DSP support by switching ChangesESP-DSP auto-detection migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
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)
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.
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 winUse defined/undefined pattern for capability macros per coding guidelines.
The capability flags
FL_FFT_ESP_DSP_AVAILABLEandFL_FFT_ESP_DSP_ACTIVEshould follow the Type 3 pattern fromagents/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 definedstyle 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 +#endifThis would also require updating line 114 to use
#ifdef FL_FFT_ESP_DSP_AVAILABLEand line 31 inAudioFftParity.inoto 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
📒 Files selected for processing (2)
examples/AudioFftParity/AudioFftParity.inosrc/fl/audio/fft/fft_backend.h
Summary
Replaces the per-sketch
#define FL_FFT_USE_ESP_DSP 1opt-in with automatic detection viaFL_HAS_INCLUDE("esp_dsp.h"). ESP32 variants whose toolchain shipsesp_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 existingkiss_fftrscalar path. No user-visible knob.Closes #2629.
Why
PR #2625 landed an
@filterworkaround onexamples/AudioFftParity/AudioFftParity.inoto keep esp32c2 green after the same hardesp_dsp.h: No such file or directoryfailure. The@filterpatched 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.hinsrc/platforms/esp/32/drivers/lcd_spi/) is to gate the header inclusion onFL_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#ifndef FL_FFT_USE_ESP_DSP / #define ... 0 / #endifopt-in default block.#if FL_FFT_USE_ESP_DSP && defined(FL_IS_ESP32)with#if defined(FL_IS_ESP32) && FL_HAS_INCLUDE(\"esp_dsp.h\").#include \"fl/stl/has_include.h\"(whereFL_HAS_INCLUDElives).examples/AudioFftParity/AudioFftParity.ino// @filter: ... esp32dev ... esp32s3 ... esp32c3 ...line added in PR fix(examples): restrict AudioFftParity to ESP32 boards with esp_dsp #2625.#define FL_FFT_USE_ESP_DSP 1.#if !FL_FFT_ESP_DSP_AVAILABLEempty-sketch fallback already handles the no-esp_dsp ESP32 variants; no new branching needed.Test plan
@filtershould 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
Documentation