Skip to content

usb_audio USBSpeaker class & enabled on nordic#11062

Merged
dhalbert merged 10 commits into
adafruit:mainfrom
FoamyGuy:usb_audio_output_speaker
Jun 23, 2026
Merged

usb_audio USBSpeaker class & enabled on nordic#11062
dhalbert merged 10 commits into
adafruit:mainfrom
FoamyGuy:usb_audio_output_speaker

Conversation

@FoamyGuy

Copy link
Copy Markdown
Collaborator

Added USBSpeaker implementation that can take audio from a computer over USB and integrate with existing audio APIs. You can apply effects with audiospeed and similar modules, and ultimately pipe it to an output source like I2SOut

I also tested USBMicrophone on RP2350, nrf52840, and samd51 successfully. Right now this PR enables usb_audio for the nordic port which required a few changes to handle the way isosyncronous endpoints are handled under nordic. I've left it disabled on atmel port for now, I had to disable some other things to make room for it and I think there will be a fair number of boards that will overflow.

@FoamyGuy

Copy link
Copy Markdown
Collaborator Author

Is the best way to handle the ones that overflowed from nordic port to add the config disabling them individually to their mpconfigboard.mk files? Or is there some higher level switch that exists already or we could create that would allow turning off the swath of them at once?

@FoamyGuy

Copy link
Copy Markdown
Collaborator Author

The latest commit limits this to only nrf52840 and boards with external flash. That looks to have resolved all of the overflowing ones. Thanks for the tip @dhalbert.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now that you've added USBSpeaker, I'm wondering about the API. If you look at usb_midi, you see that usb_midi.enable() is just on/off. The PortIn and PortOut objects are not constructable, but are just available as pre-created singletons.

In the current usb_audio API, what would happen if you tried to create more than one USBSpeaker or USBMicrophone? I would think it would or should fail.

I'm thinking maybe USBSpeaker and USBMicrophone should also be fetchable singletons (or None) as in usb_midi, and not actually constructable.

The usb_audio.enable() call is somewhat confusing because the direction parameter doesn't relate directly to speakr or microphone. Suppose instead it were something like usb_audio.enable(speaker=True/False, microcphone=True/False, ... <other current optional params)?

@FoamyGuy

Copy link
Copy Markdown
Collaborator Author

The latest commits change USBMicrophone and USBSpeaker to singletons accessed on the usb_audio module. I put them directly on the module instead of in a tuple like usb_midi.ports because I think it makes the API more descriptive to access them by name instead of index.

enable() is also changed to use speaker and microphone boolean arguments and the Direction enums are removed.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make the instance names be usb_microphone and usb_speaker, instead of the being the class names. Expose the class names but forbid user-initiated creation. This is analogous to _bleio.Adapter vs _bleio.adapter, and microcontroller.Processor vs microcontroller.cpu, and you could take the coding patterns from there.

@FoamyGuy

Copy link
Copy Markdown
Collaborator Author

singletons are renamed to usb_microphone and usb_speaker in the latest commit.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix to the speaker example., Works nicely for me! This pair of this is a very nice addition!

@dhalbert dhalbert merged commit de67b63 into adafruit:main Jun 23, 2026
225 checks passed
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.

2 participants