Author Topic: UAC 1.0 Record/Playback sample rate conflict  (Read 16397 times)

jb

  • Member
  • ***
  • Posts: 26
UAC 1.0 Record/Playback sample rate conflict
« on: July 18, 2017, 01:25:16 pm »
Our project is USB Audio Class 1.0 Full Speed with playback and recording interfaces which can be used at the same time, and should work with the OS built-in drivers.

Our CODEC only supports a single sample rate for both input and output (which is the most common way these are used).

There are only 3 alt settings for each interface: 0 bandwidth, 16-bit, and 24-bit.  It's asynchronous in and out with explicit feedback.

In Mac OS X, changing the sample rate of input also changes output, so there is no problem, but in Windows it can be set to record and play at different rates.  Our hardware doesn't support this, and our firmware fails in this case.

The manufacturer's suggested solution is to ignore input alt setting changes while the output is playing and vice versa.  (The ignored endpoint sends NAKs, if I understand correctly.  Bus analyzer shows "periodic timeout" and recording software just stalls, for instance.)   

This doesn't seem like the best method, though, since it will also ignore a good change by the user, too (correcting the sample rate of one interface to match the other during playback) and some OSes send all zeros on the endpoints continuously even when you're not actively playing or recording, which prevents anything from being changed.

(Also, the alt setting change and sample rate request are technically independent, right?  Though it seems every OS sends both at the same time, even if the alt setting has not been changed.)

Any suggestions on how to handle this better?

(I think UAC 2.0's clock descriptors would prevent the computer from requesting this?  But Windows doesn't support UAC 2.0 yet.)

Also we aren't technically required to honor a Set sampling rate request (5.2.3.2.3.1 Sampling Frequency Control), but Windows and OS X both assume that we have, and never send a Get sample rate request to confirm that it was changed, so they send the wrong rate of data.

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #1 on: July 18, 2017, 03:45:49 pm »
Hmm..  USB Complete says

Quote
Isochronous transactions don’t use NAK because they have no handshake packet for returning a NAK. If a device or the host doesn’t receive transmitted isochronous data, it’s lost.

Yet ours seems to be sending NAKs, but maybe I'm reading the bus analyzer incorrectly.


Anyway, it also says

Quote
On receiving an unsupported control-transfer request, the device returns
STALL in the Data or Status stage. The device also returns STALL if the device
supports the request but for some reason can’t take the requested action. For
example, if the host sends a Set Configuration request to set the device configuration
to 2, and the device supports only configuration 1, the device returns STALL.

So if we support sample rate requests, but not the particular sample rate that was requested at that time, we should return STALL to indicate this?

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #2 on: July 19, 2017, 05:28:10 pm »
Seems like this is the right thing to do.  UAC1.0 says:

Quote
In principle, all requests are optional. If an audio function does not support a certain request, it must
indicate this by stalling the control pipe when that request is issued to the function.

When I do this, the OS gives up and switches the interface back to zero bandwidth setting, which seems ok.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #3 on: July 19, 2017, 08:33:06 pm »
I agree this sounds like a reasonable way to handle it. Thanks for reporting what you tried.

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #4 on: August 08, 2017, 02:48:49 pm »
Does this implementation look right?

Playback is already active.  Computer turns on recording interface, then does a set sample rate request.  Setup stage completes, then Data stage (which contains the requested sample rate), at which point the device decides that the requested sample rate conflicts with the already active stream, so it STALLs during the Status stage.  The computer then gives up and turns the recording interface back to zero bandwidth.

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #5 on: August 08, 2017, 02:50:39 pm »
Actually I can't upload a screenshot of the USB trace, it says


Quote
An Error Has Occurred!
The attachments upload directory is not writable. Your attachment or avatar cannot be saved.


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #6 on: August 08, 2017, 09:33:20 pm »
If the device rejects the requested sample rate (with STALL), it makes sense the the host might want to start over.


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #7 on: August 09, 2017, 11:49:47 am »
Attachment uploads should be working now.

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #8 on: August 10, 2017, 12:52:21 pm »
Does this USB trace look right?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #9 on: August 12, 2017, 11:52:41 am »
I see a Setup packet and OUT Data packet followed by an IN packet with STALL in the Status stage, nothing unusual there. Is there something else you are concerned about?

jb

  • Member
  • ***
  • Posts: 26
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #10 on: August 12, 2017, 12:14:43 pm »
nothing unusual there

That's all I needed to hear. Thank you!

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UAC 1.0 Record/Playback sample rate conflict
« Reply #11 on: August 12, 2017, 12:51:12 pm »
You're welcome!