Skip to content

Conversation

@ManuelW77
Copy link

@ManuelW77 ManuelW77 commented Jul 2, 2025

Added Broadcast for ESP32s2, i got Multicast never to work.

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio synchronization reliability for ESP32-S2 and ESP32-C3 devices by updating UDP transmission and connection methods.
    • Enhanced compatibility for audio sync across different ESP32 hardware variants.
    • Added debug output to assist with troubleshooting audio data transmission.

…ESP32-C3 hinzu

Added Broadcast for ESP32s2, i got Multicast never to work.
@coderabbitai
Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The code updates UDP audio synchronization logic to distinguish between ESP32, ESP32-S2, and ESP32-C3 platforms. For ESP32-S2 and ESP32-C3, UDP broadcast is used instead of multicast for audio data transmission and connection setup. Conditional compilation and debug output were also adjusted to include these variants.

Changes

File(s) Change Summary
usermods/audioreactive/audio_reactive.h Modified UDP audio sync to use broadcast on ESP32-S2/C3, multicast on others; updated connection and loop logic; added debug print.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant AudioReactive
    participant UDP
    participant Network

    App->>AudioReactive: loop()
    AudioReactive->>AudioReactive: (conditional) transmitAudioData()
    alt ESP32-S2 or ESP32-C3
        AudioReactive->>UDP: Send broadcast packet (255.255.255.255:audioSyncPort)
    else ESP32 or others
        AudioReactive->>UDP: Send multicast packet (multicastIP:audioSyncPort)
    end
    UDP->>Network: Transmit packet
Loading

Poem

Hopping through code with nimble delight,
Now S2 and C3 send their packets right!
Multicast for some, broadcast for new,
Audio sync flows—no bugs in view.
With a twitch of my nose and a debug cheer,
The music hops on, crisp and clear!
🐇🎵


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af3476c and fa646c7.

📒 Files selected for processing (1)
  • usermods/audioreactive/audio_reactive.h (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: DedeHai
PR: MoonModules/WLED-MM#248
File: usermods/audioreactive/audio_reactive.h:199-200
Timestamp: 2025-06-30T17:53:37.189Z
Learning: In WLED AudioReactive usermod, when using ArduinoFFT (enabled via UM_AUDIOREACTIVE_USE_ARDUINO_FFT), it's acceptable and necessary to redefine the global sqrt macro to sqrtf within the conditional compilation block for performance optimization. This is a specific requirement for ArduinoFFT optimization that can provide 10-50% performance improvement on ESP32.
usermods/audioreactive/audio_reactive.h (2)

undefined

<retrieved_learning>
Learnt from: DedeHai
PR: #248
File: usermods/audioreactive/audio_reactive.h:199-200
Timestamp: 2025-06-30T17:53:37.189Z
Learning: In WLED AudioReactive usermod, when using ArduinoFFT (enabled via UM_AUDIOREACTIVE_USE_ARDUINO_FFT), it's acceptable and necessary to redefine the global sqrt macro to sqrtf within the conditional compilation block for performance optimization. This is a specific requirement for ArduinoFFT optimization that can provide 10-50% performance improvement on ESP32.
</retrieved_learning>

<retrieved_learning>
Learnt from: DedeHai
PR: #248
File: usermods/audioreactive/audio_reactive.h:1121-1121
Timestamp: 2025-06-30T17:58:27.954Z
Learning: In WLED AudioReactive usermod's runMicFilter function, the different cutoff frequencies between float (80Hz) and integer (90Hz) FFT implementations are intentional. The higher 90Hz cutoff for integer math helps preserve precision by avoiding overly aggressive filtering where integer arithmetic limitations could compound errors. The 10Hz difference between 80Hz and 90Hz is negligible from an audio performance standpoint but provides better precision for integer calculations.
</retrieved_learning>

🔇 Additional comments (3)
usermods/audioreactive/audio_reactive.h (3)

1726-1742: LGTM! Broadcast implementation for ESP32-S2/C3 is correct.

The platform-specific handling using UDP broadcast (255.255.255.255) for ESP32-S2 and ESP32-C3 instead of multicast is a valid workaround for these variants. The implementation correctly maintains backward compatibility with the original ESP32.


2182-2189: UDP connection setup looks good.

The use of regular fftUdp.begin(audioSyncPort) for ESP32-S2 and ESP32-C3 is consistent with the broadcast approach in transmitAudioData(). The connection logic maintains proper error handling and status tracking.


2419-2432: Platform support extension is appropriate.

Including ESP32-S2 and ESP32-C3 in the UDP transmit mode conditional compilation ensures these variants can send audio data using the broadcast method implemented in transmitAudioData().

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netmindz
Copy link
Collaborator

netmindz commented Jul 2, 2025

Rather than base the change based on suspected bug with certain esp32 varients, if we are going to have broadcast, then it should a a checkbox option as part of the sync settings so that it can also help with networks with broken multicast (which is why that option was added to the WLED Audio Server)

Copy link
Collaborator

@netmindz netmindz left a comment

Choose a reason for hiding this comment

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

Please make a checkbox, not based on chip type as I have confirmed there is no issue with the sync with S2 on known-good network

#endif

#ifdef ARDUINO_ARCH_ESP32
#if defined(ARDUINO_ARCH_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this change is not necessary, because ARDUINO_ARCH_ESP32 is defined on all esp32 boads (not just on the classic esp32)

transmitData.FFT_MajorPeak = FFT_MajorPeak;

#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3)
// ESP32-S2 and ESP32-C3: Use broadcast like the working Python script
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is "the working python script" ?

@softhack007
Copy link
Collaborator

softhack007 commented Oct 21, 2025

Please make a checkbox, not based on chip type

I fully agree with @netmindz here. The problem cannot be related to chip type as some people have working setups - in fact my "educated guess" is that the wifi router starts to block our multicast packets at some time. For example, older german Telekom "speedport" routers are regularly cutting the WLED audiosync Multicast connection also with esp32 or -S3.

It would be a nice enhancement to offer "use Broadcast instead of Multicast" for all chip types.

}

if ((audioSyncPort > 0) && (audioSyncEnabled > AUDIOSYNC_NONE)) {
#ifdef ARDUINO_ARCH_ESP32
Copy link
Collaborator

@softhack007 softhack007 Oct 21, 2025

Choose a reason for hiding this comment

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

not necessary to remove this (see my other comment)

@softhack007
Copy link
Collaborator

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

3 participants