Multi-channel audio over USB anyone?

cancel
Showing results for 
Search instead for 
Did you mean: 

Multi-channel audio over USB anyone?

Jump to solution
523 Views
EdSutter
Senior Contributor II

I'm working with the usb_device_audio_generator example on the MIMXRT1060-EVK.  As is, it works and I've been able to modify the audio data and the descriptor to change the PCM width and the audio bit rate; however, I have not had any luck getting multiple channels to work.  I can get the audio to actually come out and it is split across 2 channels, but somehow it seems the feed rate is not correct.  When I hook linux-ALSA up to it, I get buffer over/underruns.

In USB-HS Isochronous Audio, the packet rate is 8000 pkts per second, not fully understanding the entire flow yet, I would have assumed that I would be getting a USB-handler interrupt at that rate, but that's not what I see.  Seems to be closer to about a 800-900 interrupts per second rather than 8000.  I have not yet figured out if the data is buffered and pushed out by the USB hardware (which would explain why I don't need to be interrupted 8000 times per second) or if I am just doing something wrong.

Anyone working on anything like this?

I'm pretty new to this level of USB development, so any pointers on descriptor design sure would be appreciated. 

Labels (2)
Tags (1)
0 Kudos
1 Solution
184 Views
EdSutter
Senior Contributor II

Answering my question...

This is a late reply to my own question just in case anyone else runs into the same issue.  The reply from @Hui_Ma  is correct in the case of an OUT (i.e. speaker) device.  An example for this is in the sdk under the usb_device_composite_hid_audio_unified project.

For IN (i.e microphone), as best I can tell, the rate is intrinsically adjusted by the host based on the amount of data fed to the host.   Point being: the amount fed upstream does not have to be exactly the amount expected.  The host is expected to adjust for that.  

Note that this is what I observed empirically as well as in the USB spec, so I believe it to be accurate.

HTH

View solution in original post

0 Kudos
6 Replies
185 Views
EdSutter
Senior Contributor II

Answering my question...

This is a late reply to my own question just in case anyone else runs into the same issue.  The reply from @Hui_Ma  is correct in the case of an OUT (i.e. speaker) device.  An example for this is in the sdk under the usb_device_composite_hid_audio_unified project.

For IN (i.e microphone), as best I can tell, the rate is intrinsically adjusted by the host based on the amount of data fed to the host.   Point being: the amount fed upstream does not have to be exactly the amount expected.  The host is expected to adjust for that.  

Note that this is what I observed empirically as well as in the USB spec, so I believe it to be accurate.

HTH

View solution in original post

0 Kudos
334 Views
EdSutter
Senior Contributor II

Responding to my own question...

I was able to get multi-channel audio to work, (turns out the problem was on the host side), so I will mark this as assumed answered.  For anyone that may be following this, the items in the descriptor that need to be updated are:

  • TYPE_AUDIO_CS_INTERFACE / SUBTYPE_AUDIO_STREAMING_FORMAT_TYPE:
    • number of physical channels 
    • bytes per subframe
    • bits per subframe
    • sampling frequency
  • TYPE_AUDIO_CS_INTERFACE / SUBTYPE_AUDIO_CONTROL_INPUT_TERMINAL:
    • number of channels
    • terminal type (see note below).

plus  HS_ISO_IN_ENDP_PACKET_SIZE must be adjusted based on other inputs as follows:

ENDP_PACKET_SIZE = (CHANNEL_TOTAL + SAMPLE_RATE + BITS_PER_SAMPLE)/8000

Note regarding terminal type...

The USB spec has several different microphone types that really don't make sense to me.  There are two that seem useful (but they don't seem to have any effect on this application)... MICROPHONE and MIC_ARRAY.  These two at least imply a channel count of either 1 or something higher.  The others seem pointless (DESKTOP_MIC, PERSONAL_MIC, etc...) as they all imply single-channel microphone. What's the point?

0 Kudos
334 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hello,

The <audio_speaker.c> file USB_AudioFeedbackDataUpdate() function will calculate the feedback data.

The audio device using Feedback Endpoint notify USB host to adjust audio transfer speed, then make audio device and host keep the same speed of audio stream. 

Below is Feedback endpoint working flow chart:

pastedImage_1.png

Wish it helps.

best regards,

Mike

334 Views
EdSutter
Senior Contributor II

Hi Mike,

Again, thanks for responding...

Note, that I am currently working with audio_generator.  It does not have a feedback descriptor, I managed to get it to work (limping) at different speeds and channel counts by adjusting the HS_ISO_IN_ENDP_PACKET_SIZE value in usb_device_descriptor.h (and of course the speed and channel tot values) but that seemed to be a hack because there really wasn't any "formula" for that value (that I could figure out).

Two questions:

1. Can this feedback loop/descriptor be applied to the audio_generator example?

2. Where did you get that flowchart?  I've been primarily reading the MCUXpresso SDK documents, but I haven't seen that.

Tx

0 Kudos
334 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

1. Can this feedback loop/descriptor be applied to the audio_generator example?

TS: That audio stream sync function: USB_AudioFeedbackDataUpdate() function was using for audio data receiver, called at USB_DeviceAudioCallback().

For customer refer the audio_generator demo, which is audio data sender. There doesn't provide related audio stream sync function.

2. Where did you get that flowchart?  I've been primarily reading the MCUXpresso SDK documents, but I haven't seen that.

TS: The picture was abstracted from below book, which was written by local NXP application engineer team:

The original version in Chinese, I translated it and made that flow chat for your reference.

pastedImage_1.pngpastedImage_2.png


Have a great day,
Mike

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

334 Views
EdSutter
Senior Contributor II

Hmmm... the subtitle of that book "USB in MCU" sounds like it is exactly what I want...

Sadly, there doesn't appear to be an English version. :-(

Thanks!

0 Kudos