CircuitPython USB Audio

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ihab
 
Posts: 62
Joined: Tue May 17, 2016 5:20 pm

CircuitPython USB Audio

Post by ihab »

Hi folks,

Is there a way to support USB Audio via CircuitPython, writing to the DAC on the microcontroller (where this is supported in hardware)? My ItsyBitsy M4 shows up with:

Code: Select all

C:  #Ifs= 6 Cfg#= 1 Atr=80 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=02 Prot=00 Driver=cdc_acm
E:  Ad=81(I) Atr=03(Int.) MxPS=  64 Ivl=16ms
I:  If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_acm
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
I:  If#= 2 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E:  Ad=03(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=83(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
I:  If#= 3 Alt= 0 #EPs= 2 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
E:  Ad=04(O) Atr=03(Int.) MxPS=  64 Ivl=8ms
E:  Ad=84(I) Atr=03(Int.) MxPS=  64 Ivl=8ms
I:  If#= 4 Alt= 0 #EPs= 0 Cls=01(audio) Sub=01 Prot=00 Driver=snd-usb-audio
I:  If#= 5 Alt= 0 #EPs= 2 Cls=01(audio) Sub=03 Prot=00 Driver=snd-usb-audio
E:  Ad=05(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=85(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
but despite snd-usb-audio, it doesn't show up in my OS as a sound card.

Ihab

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: CircuitPython USB Audio

Post by mikeysklar »

I don't think I've seen this type of usage before. Are you trying to use your ItsyBitsy M4 as a USB Audio device when plugged into a linux box? If so, I don't see a way to do that.

You can write audio files to the DAC, but the code would have to be loaded onto the ItsyBitsy M4 something like this:

Code: Select all

import time,random,board
from audiocore import WaveFile
from audioio import AudioOut as AudioOut # only DAC
wave_file = open("laser20.wav", "rb")
wave = WaveFile(wave_file)
audio = AudioOut(board.A0)  # must be DAC-capable pin, A0 on QTPy Haxpress
while True:
  print("audio is playing:",audio.playing)
  if not audio.playing:
    audio.play(wave)
    wave.sample_rate = int(wave.sample_rate * 0.90) # play 10% slower each time
  time.sleep(0.1)
https://learn.adafruit.com/todbot-circu ... ac-3113967

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: CircuitPython USB Audio

Post by danhalbert »

The "audio" USB device stuff you see is really MIDI, not regular audio. MIDI support in USB is part of audio support.

User avatar
ihab
 
Posts: 62
Joined: Tue May 17, 2016 5:20 pm

Re: CircuitPython USB Audio

Post by ihab »

Are you trying to use your ItsyBitsy M4 as a USB Audio device when plugged into a linux box? If so, I don't see a way to do that.
That was my hope. :) Thank you for the info!
The "audio" USB device stuff you see is really MIDI, not regular audio.
Got it.

Thanks everyone,

Ihab

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”