guild icon
Toit
#USB Audio Class Device
Thread channel in help
z3ugma
z3ugma 08/03/2025 04:34 AM
I am aiming to make an ESP32-S3:

Appear as a USB Audio Class Device when plugged into a host PC

Receive digital audio (PCM) from the host.

Decode the audio and play it into a DAC/amp

An alternative plan I have looked at would be:
1. USB Audio Class Support
use the TinyUSB stack, which is supported in ESP-IDF and Arduino-ESP32

Implement a UAC1 or UAC2 sink device (only needs to receive audio).

2. Audio Streaming Interface
The host sends PCM frames (typically 16-bit, stereo, 44.1kHz or 48kHz) over isochronous USB endpoints.

define a USB descriptor that tells the host that the device supports audio streaming at certain formats.

3. Audio Output Path
Streamed audio is written to a DMA-capable I2S buffer, which outputs to a DAC to the headphone amp

Has anyone implemented the UAC2 or UAC1?

Something like [UAC 2.0 ](https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_overview/usb_device_solutions.html#usb-audio-device-solution)
z3ugma
z3ugma 08/03/2025 04:39 AM
maybe the hint is to look at https://github.com/hathach/tinyusb?tab=readme-ov-file#os-abstraction-layer and see that TinyUSB could be a bundled C file and expose an API to Toit?
An open source cross-platform USB stack for embedded system - hathach/tinyusb
floitsch
floitsch 08/03/2025 01:54 PM
I have played with I2S and managed to play audio through it. Spottune.com also uses I2S (iirc).

afaik nobody has yet used USB together with Toit. Until it is exposed through primitives, bundling a C library could indeed be a good solution. Have a look at https://docs.toit.io/tutorials/misc/c-service to see how Toit can communicate with C.
The biggest downside of this approach is that you need to build your own envelope (and maintain it).

My suggestion, if you are for it: try to get things working with tiny-usb as an external library, and if the API surface isn't too big, we can then try to integrate tiny-usb through primitives, making it a first-class citizen.
z3ugma
z3ugma 08/04/2025 03:36 PM
@MichaelK https://discord.com/channels/918498540232253480/918498540232253483/1401859279958573106

I saw you asked a similar question to this one here in the general channel
MichaelK
MichaelK 08/04/2025 03:44 PM
I was asked to write a post in help
z3ugma
z3ugma 08/04/2025 03:49 PM
yeah, check out where this thread is?
z3ugma
z3ugma 08/04/2025 03:49 PM
z3ugma
z3ugma 08/04/2025 03:49 PM
I'm saying... I am also looking for solutions that involve the S3 and it being a USB device
8 messages in total