Skip to content

update AR usermod with proper V5 support (new API) - #5764

Open
DedeHai wants to merge 3 commits into
wled:mainfrom
DedeHai:AR_V5_update
Open

update AR usermod with proper V5 support (new API)#5764
DedeHai wants to merge 3 commits into
wled:mainfrom
DedeHai:AR_V5_update

Conversation

@DedeHai

@DedeHai DedeHai commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Add support for all ESPs on V5.
I2S is updated to the new API, tested and working on ESP32 and C3
The I2S "ADC" interface is no longer supported, instead the normal "continuous sampling" ADC interface is used. As a bonus of using this, all ESP32 variants now support analog mics as the API is the same. ESP32 still uses I2S DMA sampling as before, just the interface changed.

Tested analog input on C3, ESP32 and C6 - fully working both with and without I2S_GRAB_ADC1_COMPLETELY.
There is one issue though: even if not using I2S_GRAB_ADC1_COMPLETELY, analogRead() wont work. In order to make it work, the continuous ADC would have to be deinitialized and re-initialized each loop. Doable but not a pretty solution - and not the one we should use. What would be much better is so actually use continuous sampling in the background and only stop that if something wants to use the ADC - i.e. pin manager or battery usermod (or some other usermod) which read at intervals of 250ms or even more. In order to do this, we need an ADC manager (or a general hardware manager) that handles it properly instead of having the AR usermod set up the ADC and having to free it just in case something else wants to use it.

edit:
this is an intermediate solution and this code should be migrated to the out-of-tree AR usermod in a next step.

edit2:
forgot to mention: I did not check if the V4 path still works or if there are any misplaced ifdefs for that

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio-reactive microphone compatibility across ESP32 variants and newer ESP-IDF versions.
    • Added more reliable support for I2S, PDM, and analog microphone capture.
    • Fixed analog microphone setup, configuration handling, and audio sample processing.
    • Improved ADC capture initialization, validation, cleanup, and error handling.
    • Enabled consistent audio-reactive functionality across additional ESP32 build targets.

@coderabbitai

coderabbitai Bot commented Jul 30, 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: 41948755-8ddd-411e-9cb4-824dd8b84042

📥 Commits

Reviewing files that changed from the base of the PR and between 98ecc79 and 4de8907.

📒 Files selected for processing (2)
  • usermods/audioreactive/audio_reactive.cpp
  • usermods/audioreactive/audio_source.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • usermods/audioreactive/audio_reactive.cpp
  • usermods/audioreactive/audio_source.h

Walkthrough

AudioReactive now supports ESP-IDF v5 I2S channel APIs and continuous ADC analog microphones. It preserves ESP-IDF v4 paths, uses capability-based analog-microphone guards, and centralizes audioreactive usermod selection across ESP32 environments.

Changes

AudioReactive ESP-IDF 5 compatibility

Layer / File(s) Summary
Centralize audioreactive usermod selection
platformio.ini
ESP32 target environments now inherit custom_usermods from ${common.default_usermods}, whose value is audioreactive.
Refactor I2S microphone sources
usermods/audioreactive/audio_source.h
I2S initialization, slot selection, sample reads, cleanup, codec channels, and SPH0654 handling now use ESP-IDF v5 APIs where applicable while retaining v4 branches.
Add continuous ADC analog microphones
usermods/audioreactive/audio_source.h, usermods/audioreactive/audio_reactive.cpp
AdcContinuousSource and capability-based guards support continuous ADC selection, analog-microphone configuration, and related UI output.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AudioReactive
  participant AdcContinuousSource
  participant ESPIDF_ADC
  AudioReactive->>AdcContinuousSource: initialize analog microphone
  AdcContinuousSource->>ESPIDF_ADC: configure continuous ADC
  AudioReactive->>AdcContinuousSource: read microphone samples
  AdcContinuousSource->>ESPIDF_ADC: acquire ADC frames
  ESPIDF_ADC-->>AdcContinuousSource: ADC samples
  AdcContinuousSource-->>AudioReactive: scaled FFT samples
Loading

Possibly related PRs

  • wled/WLED#4592: Both changes modify audioreactive usermod build configuration.
  • wled/WLED#5048: Both changes update ESP32 target support for AudioReactive.
  • wled/WLED#5749: Both changes address ESP-IDF v5 AudioReactive compatibility.

Suggested labels: enhancement, hardware, major, usermod, V5

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 summarizes the main change: adding ESP-IDF V5 support to the AR usermod with the new API.
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.

@DedeHai
DedeHai requested a review from softhack007 July 30, 2026 19:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (3)
usermods/audioreactive/audio_source.h (2)

526-530: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

%d format specifier for size_t arguments.

bytes_wanted/bytes_read are size_t; use %u/%zu to avoid mismatched varargs in debug builds.

🤖 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 `@usermods/audioreactive/audio_source.h` around lines 526 - 530, Update the
DEBUGSR_PRINTF call in the audio sample read check to use a format specifier
compatible with the size_t variables bytes_wanted and bytes_read, preferably %zu
for both arguments, while preserving the existing failure handling.

331-344: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

err is left at its previous value if the PDM #if body is compiled out.

Practically unreachable (the unsupported case returns earlier at line 300), but the branch is fragile if the guards ever diverge; a #else err = ESP_FAIL; makes the intent explicit.

🤖 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 `@usermods/audioreactive/audio_source.h` around lines 331 - 344, Update the
usePDM branch around i2s_channel_init_pdm_rx_mode so the
SOC_I2S_SUPPORTS_PDM_RX-disabled path explicitly assigns ESP_FAIL to err, while
preserving the existing initialization and _bytesPerSample behavior when PDM RX
is supported.
platformio.ini (1)

423-423: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Typo in comment: "audiorective" → "audioreactive".

✏️ Proposed fix
-custom_usermods = ${common.default_usermods} ;; ToDO: audiorective compiles, but not tested on C5 yet
+custom_usermods = ${common.default_usermods} ;; ToDO: audioreactive compiles, but not tested on C5 yet

Also applies to: 478-478

🤖 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 `@platformio.ini` at line 423, Correct the comment typo from “audiorective” to
“audioreactive” in both occurrences of the custom_usermods configuration
comments, including the additional occurrence noted by the review.
🤖 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.

Inline comments:
In `@usermods/audioreactive/audio_source.h`:
- Around line 516-518: The sampling hot path uses runtime-sized stack VLAs for
rawBuf, risking FFT-task stack exhaustion. Replace both rawBuf declarations in
the relevant sampling method with a fixed BLOCK_SIZE-derived buffer or a member
buffer allocated once during initialize(), using d_malloc()/p_malloc() if
dynamic storage is required; preserve the existing sample-processing behavior
without VLAs or String allocations.
- Around line 899-906: Remove the duplicated return statement in the ADC driver
error branch, leaving a single return after cleanup in the initialization flow.
- Around line 941-962: In the incomplete-frame branch after the ADC restart
logic, replace the leftover Serial.print call with the function-style
DEBUGSR_PRINTLN debug macro and fix the indentation of that branch, preserving
the existing early return and old-sample behavior.
- Around line 1020-1024: Initialize _audioPin to an invalid-pin sentinel and
update deinitialize() to call PinManager::deallocatePin only when _audioPin
contains a valid allocated pin; preserve normal cleanup after successful
allocation and leave the sentinel unchanged when allocation fails.

---

Nitpick comments:
In `@platformio.ini`:
- Line 423: Correct the comment typo from “audiorective” to “audioreactive” in
both occurrences of the custom_usermods configuration comments, including the
additional occurrence noted by the review.

In `@usermods/audioreactive/audio_source.h`:
- Around line 526-530: Update the DEBUGSR_PRINTF call in the audio sample read
check to use a format specifier compatible with the size_t variables
bytes_wanted and bytes_read, preferably %zu for both arguments, while preserving
the existing failure handling.
- Around line 331-344: Update the usePDM branch around
i2s_channel_init_pdm_rx_mode so the SOC_I2S_SUPPORTS_PDM_RX-disabled path
explicitly assigns ESP_FAIL to err, while preserving the existing initialization
and _bytesPerSample behavior when PDM RX is supported.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6abff830-78e1-445b-812a-7ce6ceb66d96

📥 Commits

Reviewing files that changed from the base of the PR and between d619d46 and db218a7.

📒 Files selected for processing (3)
  • platformio.ini
  • usermods/audioreactive/audio_reactive.cpp
  • usermods/audioreactive/audio_source.h

Comment thread usermods/audioreactive/audio_source.h
Comment thread usermods/audioreactive/audio_source.h
Comment thread usermods/audioreactive/audio_source.h
Comment thread usermods/audioreactive/audio_source.h
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