Skip to content

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

Closed

Description

@zackees

Goal

Eliminate the per-sketch FL_FFT_USE_ESP_DSP define and the user-facing @filter it forces, by routing ESP-DSP through the scalar polyfill that already exists in fl::audio::fft. Users should never need to opt in OR out — the right backend should select automatically based on what the toolchain actually ships.

Background

PR #2625 just landed an @filter workaround on examples/AudioFftParity/AudioFftParity.ino to keep esp32c2 (and likely esp32s2/h2/c5) green. Root cause was:

  1. The example sets #define FL_FFT_USE_ESP_DSP 1
  2. src/fl/audio/fft/fft_backend.h:101 #include "esp_dsp.h" whenever that define + FL_IS_ESP32 are both true
  3. esp_dsp.h isn't in every ESP32 toolchain bundle (low-end RISC-V parts don't have it)
  4. Result: hard compile error on boards where the header is missing

The @filter works around the symptom but the underlying design is wrong: any user-authored sketch that opts into ESP-DSP for performance will hit the same wall on a non-supported board, with no diagnostic better than "esp_dsp.h: No such file or directory."

Proposal — eliminate the define

  1. Auto-detect esp_dsp availability at preprocessor time:

    #if defined(FL_IS_ESP32) && FL_HAS_INCLUDE("esp_dsp.h")
        #define FL_FFT_ESP_DSP_AVAILABLE 1
        #include "esp_dsp.h"
    #else
        #define FL_FFT_ESP_DSP_AVAILABLE 0
    #endif

    Drop the user-opt-in FL_FFT_USE_ESP_DSP entirely. FL_HAS_INCLUDE already exists in fl/stl/has_include.h and is used elsewhere in the codebase for exactly this kind of feature probe (e.g. lcd_spi gates esp_cache.h the same way).

  2. Scalar fallback is automatic. The dispatch logic at the call site already has #if FL_FFT_ESP_DSP_AVAILABLE / #else branches — the #else path uses kiss_fftr or the scalar polyfill. Switching the gate from "user opted in" to "header is present" means:

    • ESP32 boards with esp_dsp → use the hardware-accelerated backend automatically.
    • ESP32 boards without esp_dsp (C2, S2, H2, C5) → use the scalar fallback automatically.
    • Non-ESP32 (AVR/Teensy/ARM) → use the scalar fallback automatically.
  3. Drop the @filter from AudioFftParity (added in PR fix(examples): restrict AudioFftParity to ESP32 boards with esp_dsp #2625). The example becomes a parity test that runs on every ESP32 board, validating the ESP-DSP backend where present and the scalar fallback where not. Same math should pass either way.

Why this is better

  • No user-facing knobs. Users don't need to know about ESP-DSP existence. Performance just happens when the chip can deliver it.
  • No example matrix surprises. New ESP32 chips that omit ESP-DSP (or future chips that gain it) Just Work without a CI matrix update.
  • One less footgun. A user writing their own audio sketch on esp32c2 won't accidentally #define FL_FFT_USE_ESP_DSP 1 (copy-pasting from AudioFftParity) and hit a stop-the-build error.

Test plan

  • Strip FL_FFT_USE_ESP_DSP from fft_backend.h and AudioFftParity.ino.
  • Add FL_HAS_INCLUDE("esp_dsp.h") probe in fft_backend.h.
  • Remove the @filter from AudioFftParity.ino.
  • bash compile esp32c2 --examples AudioFftParity succeeds (uses scalar fallback).
  • bash compile esp32s3 --examples AudioFftParity succeeds (uses ESP-DSP).
  • bash test fl_audio_fft --cpp continues to pass on the host (scalar path).
  • AudioFftParity's runtime assertions pass on both an esp32c2 and an esp32s3 — the scalar and ESP-DSP backends produce mathematically equivalent output for the test signals.

Related

Activity

  1. added a commit that references this issue on Jun 5, 2026
    350a389
  2. moved this from Triage to Done in FastLED Trackeron Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions