-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Open
Labels
Type: Feature requestFeature request for Arduino ESP32Feature request for Arduino ESP32
Description
Related area
USB
Hardware specification
ESP32-S2, ESP32-S3
Is your feature request related to a problem?
Yes. The Arduino ESP32 core provides wrappers for USB device classes like CDC, HID, and MSC, but USB Audio Class is completely unavailable.
While TinyUSB supports USB Audio via CFG_TUD_AUDIO, this option is not enabled in the arduino-esp32 TinyUSB build. The audio class code is simply not compiled in.
This means:
- Audio callbacks like tud_audio_rx_done_post_read_cb() don't exist
- Audio descriptors cannot be registered
- There is no workaround within the Arduino framework
Even with custom descriptor code, USB Audio cannot be implemented without rebuilding the ESP32 Arduino core from source with CFG_TUD_AUDIO=1 — effectively forcing users to abandon Arduino for ESP-IDF.
Describe the solution you'd like
Add a USBAudio class following the same pattern as USBCDC, USBHIDKeyboard, etc., supporting input, output, and bidirectional audio.
Desired API
USB Speaker (host → ESP32 → I2S DAC):
#include "USB.h"
#include "USBAudio.h"
USBAudioOutput Speaker;
void onSpeakerData(uint8_t* data, size_t len) {
i2s_write(I2S_NUM_0, data, len, &written, portMAX_DELAY);
}
void setup() {
Speaker.begin(44100, 16, 2); // 44.1kHz, 16-bit, stereo
Speaker.onReceive(onSpeakerData);
USB.begin();
}
USB Microphone (I2S ADC → ESP32 → host):
#include "USB.h"
#include "USBAudio.h"
USBAudioInput Microphone;
void loop() {
i2s_read(I2S_NUM_0, buffer, sizeof(buffer), &read, portMAX_DELAY);
Microphone.write(buffer, read);
}
void setup() {
Microphone.begin(48000, 16, 1); // 48kHz, 16-bit, mono
USB.begin();
}
Full USB Audio Interface (bidirectional):
#include "USB.h"
#include "USBAudio.h"
USBAudioInterface AudioCard;
void setup() {
AudioCard.beginOutput(44100, 16, 2); // Speaker
AudioCard.beginInput(44100, 16, 2); // Microphone
AudioCard.onReceive(onSpeakerData);
USB.begin();
}
Key features
- Separate classes for output (USBAudioOutput), input (USBAudioInput), and combined (USBAudioInterface)
- Simple begin(sampleRate, bitDepth, channels) initialization
- Callback-based receive, buffer-based transmit
- Automatic UAC2 descriptor generation
- Optional volume/mute control support
- Works seamlessly with existing USB.begin() flow
### Describe alternatives you've considered
1. **Raw TinyUSB implementation** — Not possible within Arduino. Even with custom descriptor code, `CFG_TUD_AUDIO` is not enabled in the arduino-esp32 TinyUSB build, so audio callbacks and functions don't exist.
2. **Rebuilding arduino-esp32 from source** — Users could clone the core and enable `CFG_TUD_AUDIO=1`, but this defeats the purpose of using Arduino and requires maintaining a custom fork.
3. **External libraries** — No maintained Arduino ESP32 USB Audio library exists. The [ESP32-USB-Audio](https://github.com/pschatzmann/ESP32-USB-Audio) repo by pschatzmann is experimental and requires ESP-IDF modifications.
4. **ESP-IDF directly** — The only currently working option, but loses all Arduino ecosystem benefits (libraries, simple API, community support) and requires significant migration effort.
None of these alternatives provide the Arduino experience that makes ESP32 accessible to hobbyists and rapid prototyping.
### Additional context
#### Use cases this would enable
- **USB DAC** — ESP32-S3 as plug-and-play USB sound card → I2S DAC (PCM5102, MAX98357, ES9038)
- **USB Microphone** — ESP32-S3 as USB recording device from I2S/PDM mic (INMP441, SPH0645)
- **USB Audio Interface** — Bidirectional audio for effects processors, synthesizers, loopers
- **USB MIDI + Audio** — Combined MIDI controller with audio capabilities
#### Technical foundation already exists
- TinyUSB has mature Audio Class support (`CFG_TUD_AUDIO`)
- ESP-IDF's TinyUSB component includes all necessary audio headers
- Similar wrappers already exist for HID/CDC/MSC in arduino-esp32
- The implementation pattern is well-established in the codebase
#### Community interest
USB Audio on ESP32 is frequently requested in forums and discussions. Native support would unlock a whole category of audio projects for the Arduino community.
### I have checked existing list of Feature requests and the Contribution Guide
- [x] I confirm I have checked existing list of Feature requests and Contribution Guide.Metadata
Metadata
Assignees
Labels
Type: Feature requestFeature request for Arduino ESP32Feature request for Arduino ESP32