Skip to content

USB UAC garbled sound randomly (AEGHB-1103) #525

@digitalLumberjack

Description

@digitalLumberjack

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v6.0-dev-429-g36a5a71d5c, 5.3, 5.4,

Espressif SoC revision.

ESP32-s3

Operating System used.

Windows

How did you build your project?

Command line with CMake

If you are using Windows, please specify command line type.

None

Development Kit.

Custom Board

Power Supply used.

USB

What is the expected behavior?

Runs audio stream perfectly.

What is the actual behavior?

Hello, I need to use my esp32-s3 to act as a proxy between my host and an i2s DAC

Host -> USB -> EPS32-S3 -> i2s DAC -> speaker

I am working on a custom dev board that I use with esp-adf, which reads opus files and transmits the data in I2S to the DAC (PCM5102a). This allows me to be sure that the problem does not come from the board design.

I used the usb_device_uac component, and I am able to get sound with code based on the example https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/device/usb_uac

Using espressif/esp_codec_dev: 1.3.4 to send i2s data to my PCM5102.

Everything works fine, I have good quality sound on the speaker, but randomly, I get crackling sound that is inaudible. This suggests a buffer underrun (see attachment).

audio_crsipy.zip

On the host side, PulseAudio does not output any logs that could indicate that there is a problem.
The UAC device is detected as intended by usb descriptors:

Sink #0
	State: SUSPENDED
	Name: alsa_output.usb-xxxxxxx_000000001-00.analog-stereo
	Description: xxxxx Analog Stereo
	Driver: module-alsa-card.c
	Sample Specification: s16le 2ch 48000Hz
	Channel Map: front-left,front-right
	Owner Module: 53
	Mute: no
	Volume: front-left: 9619 /  15% / -50.00 dB,   front-right: 58409 /  89% / -3.00 dB
	        balance 0.84
	Base Volume: 65536 / 100% / 0.00 dB
	Monitor Source: alsa_output.usb-xxxxxx_000000001-00.analog-stereo.monitor
	Latency: 0 usec, configured 0 usec
	Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
	Properties:
		alsa.resolution_bits = "16"
		device.api = "alsa"
		device.class = "sound"
		alsa.class = "generic"
		alsa.subclass = "generic-mix"
		alsa.name = "USB Audio"
		alsa.id = "USB Audio"
		alsa.subdevice = "0"
		alsa.subdevice_name = "subdevice #0"
		alsa.device = "0"
		alsa.card = "3"
		alsa.card_name = "xxxxxxxx"
		alsa.long_card_name = "xxxxxxxxx at usb-xhci-hcd.1-1, full speed"
		alsa.driver_name = "snd_usb_audio"
		device.bus_path = "platform-xhci-hcd.1-usb-0:1:1.0"
		sysfs.path = "/devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3/3-1/3-1:1.0/sound/card3"
		device.bus = "usb"
		device.vendor.id = "1452"
		device.vendor.name = "xxxx"
		device.product.id = "5487"
		device.product.name = "xxxxx"
		device.serial = "xxxxx"
		device.string = "front:3"
		device.buffering.buffer_size = "384000"
		device.buffering.fragment_size = "192000"
		device.access_mode = "mmap+timer"
		device.profile.name = "analog-stereo"
		device.profile.description = "Analog Stereo"
		device.description = "xxxxxxxxxxxx Analog Stereo"
		module-udev-detect.discovered = "1"
		device.icon_name = "audio-card-usb"
	Ports:
		analog-output: Analog Output (type: Analog, priority: 9900, availability unknown)
	Active Port: analog-output
	Formats:
		pcm

In the esp32-s3 code, I have these logs:

I (1775) usb_uac_main: uac_device_set_volume_cb: 100
I (1796) TUSB_DESC: tud_hid_descriptor_report_cb for 0
I (1818) TUSB_DESC: tud_hid_descriptor_report_cb for 1
Clock get is valid 1
Clock get current freq 48000
Clock get is valid 1
Speaker interface 1-1 openedSpeaker interface 1-1 opened
D (1975) usbd_uac: Feedback method: 4, sample freq: 48000
Clock get is valid 1
Clock get current freq 48000
Clock get is valid 1
Speaker interface 1-1 openedSpeaker interface 1-1 opened
D (2015) usbd_uac: Feedback method: 4, sample freq: 48000
Clock get is valid 1
Clock get current freq 48000
Clock get is valid 1
Speaker interface 1-1 openedSpeaker interface 1-1 opened
D (2047) usbd_uac: Feedback method: 4, sample freq: 48000
Set speaker channel 1 volume: -50 dB (0)
I (2051) usb_uac_main: uac_device_set_volume_cb: 0
Set speaker channel 2 volume: -3 dB (94)
I (2058) usb_uac_main: uac_device_set_volume_cb: 94
  1. I tried to see if the tud buffer could be undersized compared to the expected bytes by adding
    if (bytes_remained < bytes_require)
        ESP_LOGI(“uac”, “underrun”);

here:

s_uac_device->spk_data_size = tud_audio_read(s_uac_device->spk_buf, bytes_require);

Nothing, I even checked and bytes_remained is always full (its size depends on the configuration)

  1. I checked that the audio buffer was always written completely when calling esp_codec_dev_write, which is the case.

  2. I checked that software volume management could not impact performance by disabling it.

  3. If I set CONFIG_UAC_SPK_INTERVAL_MS to 50 or 100ms, it seems to reduce the times issue occurs (not sure)

  4. I'm running the tusb task from the usb_uac component, no other "non system" tasks are running

I don't know where else to look. Do you have any ideas?

Here are my configuration files:

tusb_configuration.zip

Steps to reproduce.

.

Debug Logs.


More Information.

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions