Skip to content

Add stereo support to usb_audio#11102

Draft
relic-se wants to merge 12 commits into
adafruit:mainfrom
relic-se:usb-audio-stereo
Draft

Add stereo support to usb_audio#11102
relic-se wants to merge 12 commits into
adafruit:mainfrom
relic-se:usb-audio-stereo

Conversation

@relic-se

@relic-se relic-se commented Jul 8, 2026

Copy link
Copy Markdown

Updates USB Audio device descriptors to assume stereo operation. Mono operation (channel_count=1) is still supported although the device will enumerate as stereo.

Example Code

boot.py

import usb_audio
import usb_hid
import usb_midi

usb_hid.disable()
usb_midi.disable()

# Alter settings here to test different configurations
usb_audio.enable(
    sample_rate=48000,
    channel_count=2,
    microphone=True,
    speaker=True,
)

code.py

from synthio import Synthesizer, Note
from usb_audio import usb_microphone, usb_speaker

SAMPLE_RATE = 48000
CHANNEL_COUNT = 2

# This will need to be replaced with your hardware of choice
from relic_synthiota import Synthiota
synthiota = Synthiota(
    sample_rate=SAMPLE_RATE,
    channel_count=CHANNEL_COUNT,
)
audio = synthiota.audio

if usb_speaker is not None:
    audio.play(usb_speaker)

if usb_microphone is not None:
    synth = Synthesizer(
        sample_rate=SAMPLE_RATE,
        channel_count=CHANNEL_COUNT,
    )
    usb_microphone.play(synth)
    synth.press(Note(440))

if usb_microphone is not None or usb_speaker is not None:
    try:
        while True:
            pass
    except KeyboardInterrupt:
        pass

Notes

  • The bits_per_sample argument is removed from usb_audio.enable(...) since it is always assumed to be 16. (open to input here)
  • For operation on most devices, usb_hid (and potentially usb_midi) will need to be disabled to avoid reaching the limit of USB endpoint pairs when operating in bidirectional mode.

In Progress

  • Mono output through usb_microphone results in random noise.
  • Mono input through usb_speaker results in distorted audio.
  • Bidirectional operation is somewhat functional, but an issue with the device descriptor is causing distortion with usb_speaker. Stereo usb_microphone operates correctly.

For interest: @FoamyGuy

@FoamyGuy

FoamyGuy commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for working on this! I will test out mono speaker, and try to resolve the issues with microphone.

@mikeysklar

Copy link
Copy Markdown
Collaborator

@relic-se

#11093 (tinyusb bump) just merged, which migrates usb_audio to the TUD_AUDIO20_/AUDIO20_ names and touches tusb_config.h + usb_audio_descriptors.h, so this branch will need a rebase onto main.

@relic-se

Copy link
Copy Markdown
Author

@mikeysklar Thanks for your work here. I'll make sure to follow your guidelines closely.

@relic-se

Copy link
Copy Markdown
Author

@mikeysklar I've updated my code accordingly, and it's looking good. There are still some bugs within this PR which prevents it from being ready to merge at this time.

@relic-se

Copy link
Copy Markdown
Author

As an aside, Linus Torvalds appears to have some success with stereo headset operation on his RP2350 guitar pedal: https://github.com/torvalds/GuitarPedal/blob/main/Software/usb-device.c

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