Repository navigation
feat(audio/fft): ESP-DSP backend + AudioFftParity hardware validation harness - #2315
Conversation
Adds the full ESP-DSP real-FFT backend as groundwork for audio pipeline optimization (issue #2308 / #2254 Issue 3 follow-up) along with a hardware validation sketch. What's added: src/fl/audio/fft/fft_backend.h - Full ESP-DSP real-FFT implementation under `detail::espDspRealForward`, gated on FL_FFT_USE_ESP_DSP=1 + defined(FL_IS_ESP32). - Pattern: pack N reals as N/2 complex, run dsps_fft2r_fc32 + bit-rev, unpack conjugate-symmetric output to N/2+1 kiss_fft_cpx bins via precomputed cos/sin twiddle tables. - Updated wrapper signature: fl_fft_real_forward() now takes explicit `int N` so the ESP-DSP path can index its per-size twiddle cache (kiss_fftr_cfg is opaque). - Dispatcher still routes through kiss_fftr regardless of FL_FFT_ESP_DSP_ACTIVE — see inline comment for the int16/float type mismatch reason (FASTLED_FFT_FIXED16 default makes kiss_fft_scalar=int16_t which doesn't compose with ESP-DSP's fc32). src/fl/audio/fft/fft_impl.cpp.hpp - 7 call sites pass N (mInputSamples, mHybridMidN*2, mHybridSmallN). examples/AudioFftParity/AudioFftParity.ino (new) - Hardware sanity test: generates known signals (zero, DC, impulse, sines at bins 40/113/200) and validates mathematical properties of ESP-DSP output (DC spike at bin 0 only, flat spectrum from impulse, peaks 10x above noise floor for single tones). Emits FFT_PARITY_PASS / FFT_PARITY_FAIL on serial. - Empty setup/loop on non-ESP32 so the host example-compile stage doesn't fail. Current state on ESP32-S3 hardware: zero PASS (correct zero output) dc FAIL (output ~flat ~179 instead of DC spike) impulse FAIL (output not uniform as expected) sines FAIL So: the ESP-DSP math has a subtle bug the sanity test is catching — exactly the outcome the parity harness is meant to produce before enabling the backend in production. Header comment flags this and leaves the dispatcher on kiss_fftr. Follow-up work: debug the unpack (suspect cos/sin twiddle indexing or bit-reversal ordering). Test plan: * bash test fft -> 1/1 pass (kiss path unchanged) * bash test audio -> 1/1 pass * bash compile esp32s3 --examples AudioFftParity -> SUCCESS * bash debug AudioFftParity -> emits FFT_PARITY_FAIL (as expected currently; will flip to PASS after the math bug is fixed) See issue #2308 for the broader audio-performance plan. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds a new FFT parity verification Arduino sketch and introduces ESP-DSP backend infrastructure with conditional compilation support in the FFT backend header. Updates the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
📊 Header Compilation PerformanceTotal Time: 1174.67ms Top 5 Slowest Headers
Warnings
Full Report |
Summary
Groundwork for audio-pipeline optimization in issue #2308 (#2254 Issue 3 follow-up). Lands the full ESP-DSP real-FFT implementation + a hardware sanity-test example that validates it on actual ESP32 silicon.
The harness worked as designed — it caught a real bug in the ESP-DSP unpack. Posting as-is with the dispatcher still defaulting to kiss_fftr so nothing ships broken.
What lands
src/fl/audio/fft/fft_backend.hFull ESP-DSP real-FFT under
detail::espDspRealForward(N, in, out):dsps_fft2r_fc32+dsps_bit_rev_fc32_ansi(in-place complex FFT).kiss_fft_cpxbins using precomputedcos(2πk/N)/sin(2πk/N)tables (cached per-size in a static context).Compiled only when
FL_FFT_USE_ESP_DSP=1AND ESP32. The top-level dispatcherfl_fft_real_forward()still routes throughkiss_fftrregardless — see the inline comment for why: FastLED's defaultFASTLED_FFT_PRECISION=FASTLED_FFT_FIXED16makeskiss_fft_scalar=int16_twhich doesn't compose with ESP-DSP's float32 API. Auto-routing needs either an int16 packed-FFT variant usingdsps_fft2r_sc16or a library-wide switch toFASTLED_FFT_FLOAT. Tracked as follow-up.Dispatcher API changed: takes explicit
int N(kiss path casts tovoid; the ESP-DSP path needs it becausekiss_fftr_cfgis opaque).src/fl/audio/fft/fft_impl.cpp.hpp7 call sites updated to pass size (
mInputSamples,mHybridMidN*2,mHybridSmallN).examples/AudioFftParity/AudioFftParity.ino(NEW)Hardware sanity test. Generates 6 known signals and validates analytic properties of the ESP-DSP output:
zerodcimpulsesine@bin40sine@bin113sine@bin200Compiles on all platforms (non-ESP32 stub): empty setup/loop so the host
example-testsCI stage doesn't break.Use:
What this tells us
The pattern (~179 magnitude EVERYWHERE regardless of input) suggests the issue is either:
dsps_fft2r_fc32is different from what my unpack expects.ctx.cos_table[k-1]/sin_table[k-1]may not match what the formula expects for a given k.ctx.work[2*k, 2*k+1]may not be interpreted asRe, Imbydsps_fft2r_fc32— could be[real-array, imag-array]convention.Next step is debugging the ESP-DSP unpack by inspecting raw intermediate values from a known input. That's a focused follow-up — safer to ship this harness first (catches future regressions) and leave the dispatcher on the known-good kiss path.
Test plan
bash test fft— 1/1 pass. Kiss path unchanged.bash test audio— 1/1 pass.bash compile esp32s3 --examples AudioFftParity— succeeds.Related
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
New Features
Refactor