Skip to content

fix(audioreactive): skip i2s_set_clk() for PDM mode on IDF 5.x - #5807

Open
aenertia wants to merge 1 commit into
wled:mainfrom
aenertia:upstream-pr/audioreactive-pdm-fix
Open

fix(audioreactive): skip i2s_set_clk() for PDM mode on IDF 5.x#5807
aenertia wants to merge 1 commit into
wled:mainfrom
aenertia:upstream-pr/audioreactive-pdm-fix

Conversation

@aenertia

@aenertia aenertia commented Aug 18, 2026

Copy link
Copy Markdown

i2s_set_clk() after i2s_driver_install() kills PDM mode on ESP-IDF 5.x, producing all-zero samples from the microphone. The PDM clock is configured during driver install; calling i2s_set_clk() afterwards resets it to I2S standard mode.

Fix: guard i2s_set_clk() with if (!(_config.mode & I2S_MODE_PDM)) so PDM microphones (SPM1423, INMP441 in PDM mode) work correctly on IDF 5.x.

Also fixes PDM channel format: uses I2S_CHANNEL_FMT_ALL_LEFT/ALL_RIGHT instead of ONLY_LEFT/ONLY_RIGHT, which is required for PDM compatibility on IDF 5.x (ONLY_* variants produce silence in PDM mode).

Tested on M5StickC with SPM1423 PDM microphone.

Summary by CodeRabbit

  • Bug Fixes
    • Improved PDM microphone channel configuration for left and right channel modes.
    • Prevented unnecessary clock configuration during PDM audio initialization.
    • Preserved error handling when clock setup fails for non-PDM audio modes.

i2s_set_clk() after i2s_driver_install() kills PDM mode on ESP-IDF 5.x,
producing all-zero samples from the microphone. The PDM clock is
configured during driver install; calling i2s_set_clk() afterwards
resets it to I2S standard mode.

Fix: guard i2s_set_clk() with if (!(_config.mode & I2S_MODE_PDM)) so
PDM microphones (SPM1423, INMP441 in PDM mode) work correctly on IDF 5.x.

Also fixes PDM channel format: uses I2S_CHANNEL_FMT_ALL_LEFT/ALL_RIGHT
instead of ONLY_LEFT/ONLY_RIGHT, which is required for PDM compatibility
on IDF 5.x (ONLY_* variants produce silence in PDM mode).

Tested on M5StickC with SPM1423 PDM microphone.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bb41e349-da45-4c0b-ab8c-58d5a2eada64

📥 Commits

Reviewing files that changed from the base of the PR and between 42b2399 and 1021759.

📒 Files selected for processing (1)
  • usermods/audioreactive/audio_source.h

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


Walkthrough

PDM channel selection now uses side-specific ALL_RIGHT or ALL_LEFT formats. PDM initialization skips i2s_set_clk(), while non-PDM initialization retains existing clock setup and failure handling.

Changes

PDM I2S configuration

Layer / File(s) Summary
PDM channel format configuration
usermods/audioreactive/audio_source.h
PDM microphone selection now uses I2S_CHANNEL_FMT_ALL_RIGHT or I2S_CHANNEL_FMT_ALL_LEFT. The related text describes the selected format.
Conditional I2S clock setup
usermods/audioreactive/audio_source.h
Non-PDM sources retain i2s_set_clk() and cleanup on failure. PDM sources skip the call and log the compatibility path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 10217

The PR makes a localized audio-source change to preserve PDM microphone operation on ESP-IDF 5.x, with no actionable merge-blocking risk remaining beyond normal checks and review.

Possibly related PRs

  • wled/WLED#5764: Modifies overlapping PDM channel selection and I2S clock initialization in audio_source.h.

Suggested reviewers: softhack007

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the primary PDM-mode fix for ESP-IDF 5.x.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

aenertia added a commit to aenertia/WLED that referenced this pull request Aug 18, 2026
- pr/audioreactive-pdm-fix → wled#5807
- pr/chunked-json-fix → wled#5808
- pr/effects-fade-snap → wled#5809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant