Author Topic: USB audio class 2.0 on a microcontroller?  (Read 6066 times)

0 Members and 1 Guest are viewing this topic.

Offline SiliconWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
USB audio class 2.0 on a microcontroller?
« on: June 21, 2019, 03:24:28 pm »
I'm looking for a working example of source code implementing USB audio class 2.0 on a microcontroller supporting USB 2.0 HS. Preferrably STM32, but doesn't really matter. I've found quite a few examples for USB audio class 1.0, but pretty much nothing for USB audio class 2.0.

An alternative would be using an XMOS-based solution, but cost would be significantly higher and then there would be the time investment with the tools/language... and possibly additional cost (I'm not sure whether XMOS USB audio library is free or not...)

So if anyone has already implemented that on an MCU or knows of such projects... Thanks!



 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: USB audio class 2.0 on a microcontroller?
« Reply #1 on: June 22, 2019, 10:02:05 pm »
I've never done much with Audio on USB, but did a little search:

https://duckduckgo.com/html?q=USB+audio+class+2.0+
And among the first that popped up was Cmedia, and I had a peek at the 16page "datasheet" of th CM6610A.

They seem to think that high quality audio is just pushing more bits, and (as almost everybody seems to do nowadays) derive everything with a PLL from a cheap 12MHz crystal.

If you take audio seriously, then extremely stable and low jitter clocks are mandatory.
This seems to be a very often overlooked, or completely ignored fact.

If you want true 24 bit audio with a 192kHz klock, then you need to keep long term jitter in the DAC and ADC to within
>> 1/2^24/192000
ans =    3.1044e-13

Yep, that's 310 femto seconds.

Edit:
Oops, error. The sample rate should probably not be part of this equation, but the maximum signal frequency is, so it probably should be:
>> 1/2^24/20000
ans =    2.9802e-12
Which is 3ps instead of femto seconds. It does not matter much though, as accurate calculations need actual signals instead of a simple sine, but the general idea still stands. For good audio you need very accurate clocks.
(Accuracy is not the main goal, but stability is, But I'm afraid I'm getting a bit too anal here).

It's very easy to deduce that you need this accuracy.
For a simple sine(), the derivative is a cosine(), which has the same maximum value of 1.
Which means that the time resoultion for the samples is roughly equivalent to the time resolution.
Without the all invading trend of hyper compression which demolishes most audio nowaday's, audio regularly used to have a crest factor of 5 (or more) which makes it even worse.

Without acknowledging this, you will just design a 100 in a dozen mediocre audio gadged instead of a gread sounding device.
« Last Edit: June 28, 2019, 02:39:16 pm by Doctorandus_P »
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: USB audio class 2.0 on a microcontroller?
« Reply #2 on: June 22, 2019, 10:21:31 pm »
Well, you don't need to derive the DACs clock from USB, as you're implementing it yourself, both USB Audio 1.0 and 2.0 support asynchronous mode, allowing the device to send feedback (I believe its how full its buffer is) to the host, effectively making the device the main clock that determines how many samples to send per transfer.

Also, "high quality" is a relative and somewhat vague term.  One could argue that, with 20ppm oscillators, 20-bit @ 48kHz is "high quality".  But if you're after 192kHz (for some reason) and 24-bit, then I guess it makes sense to go equally overkill on the clocks.
 

Offline SiliconWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: USB audio class 2.0 on a microcontroller?
« Reply #3 on: June 22, 2019, 10:30:57 pm »
I'm going to use asynchronous mode indeed.
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9018
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: USB audio class 2.0 on a microcontroller?
« Reply #4 on: June 23, 2019, 01:24:32 am »
Have you considered the FX2? It handles lots of bandwidth with ease and breakout boards for it are dirt cheap thanks to its popularity as a budget logic analyzer.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline 1audio

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: us
Re: USB audio class 2.0 on a microcontroller?
« Reply #5 on: June 23, 2019, 04:25:04 am »
Look up "audio widget". It's an open source implementation of UAC2 on a more general purpose platform.

Sent from my LG-H830 using Tapatalk

 
The following users thanked this post: SiliconWizard

Offline SiliconWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: USB audio class 2.0 on a microcontroller?
« Reply #6 on: June 23, 2019, 01:09:40 pm »
Look up "audio widget". It's an open source implementation of UAC2 on a more general purpose platform.

Apparently it would be part of this: https://github.com/borgestrand/sdr-widget ?

I'm going to take a look, thanks!
 

Offline SiliconWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: USB audio class 2.0 on a microcontroller?
« Reply #7 on: June 23, 2019, 01:11:30 pm »
Have you considered the FX2? It handles lots of bandwidth with ease and breakout boards for it are dirt cheap thanks to its popularity as a budget logic analyzer.

Actually yes I have (and have already worked with FX2's in the past so that would be familiar). That's the firmware part (properly implementing UAC2) that I'm really interested in. I guess I could figure it out from the USB spec, but doing that from scratch would probably take a fair amount of time...
 

Offline DEV001

  • Contributor
  • Posts: 47
  • Country: us
Re: USB audio class 2.0 on a microcontroller?
« Reply #8 on: July 05, 2019, 07:07:31 pm »
If you want something somewhat turnkey you could use an XMOS xCORE 200 solution. They offer a USB 2.0 Audio Class dev kit which has most  of the specs you could ever want. I will admit using xTIMEcomposer and understanding their architecture takes some time but it is perfect for this type of application.

https://www.xmos.com/products/audio/kits

xCORE-200 multichannel audio platform

USB Audio Class 2.0 device
Optional Audio Class 1.0 fall-back
Low loopback latency: 3 ms
Self-powered (with Apple charging) or bus-powered
Bit perfect USB audio transfer

Info on developing audio devices: https://www.xmos.com/file/usb-audio-software-design-guide?version=latest
 

Offline ve7xen

  • Super Contributor
  • ***
  • Posts: 1193
  • Country: ca
    • VE7XEN Blog
Re: USB audio class 2.0 on a microcontroller?
« Reply #9 on: July 05, 2019, 09:08:52 pm »
I'm working on a custom design around xMOS 200 series right now, actually. To just implement a basic DAC seems pretty straightforward, if you go digging around you can find several examples with code that looks modular enough to basically just reconfigure and recompile.

Unfortunately I'm having some difficulties with the JTAG interface on my boards. Not sure if I've missed something in the design (though I've carefully reviewed the requirements several times), screwed up the assembly or fried the chip somehow or what, but I can speak to the on-chip JTAG controller, but it can't enumerate the CPU. Looking for some time to continue plugging away at it. The BOM is kinda pricey so I don't just want to throw a bunch of money at building another board if it's a design issue...
73 de VE7XEN
He/Him
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf