Skip to contentSkip to conversation

ALSA: snd-usb: Some small fixes to make Playback Design products work

PATCH Applied Daniel Mack 5 participants 34 messages Mar 17, 2013 – Mar 28, 2013 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ALSA: snd-usb: Some small fixes to make Playback Design products work

Thanks to Andreas, I got my hands on a Playback Design MPD-3 and hacked up some small hanges necessary to make it fully work with snd-usb.

The device reports 0x80000000 in the bmFormats field of two of three of its alternate settings, which wrongly made the driver believe it's a usual PCM endpoint (actually due to a fix-up fallback). However, bit 31 of this mask in fact denotes 'raw data'.

The effect of this issue is that in addition to the first altsetting with a bit depth of 24, the driver exposed 8-bit and 16-bit native audio formats on the raw data endpoints, which do not work as expected.

Also, those devices need a 50ms delay after switching the USB interface.

Thanks,
Daniel

Daniel Mack (3):
ALSA: snd-usb: handle the bmFormats field as unsigned int
ALSA: snd-usb: handle raw data format of UAC2 devices
ALSA: snd-usb: add delay quirk for "Playback Design" products

 include/linux/usb/audio-v2.h |    2 ++
 sound/usb/format.c           |   20 ++++++++++++--------
 sound/usb/format.h           |    2 +-
 sound/usb/pcm.c              |    7 +++++++
 sound/usb/stream.c           |    2 +-
 5 files changed, 23 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 ALSA: snd-usb: handle the bmFormats field as unsigned int

This field may use up to 32 bits, so it should be handled as unsigned int.

---
 sound/usb/format.c |    9 +++++----
 sound/usb/format.h |    2 +-
 sound/usb/stream.c |    2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
sound/usb/format.c +5 -4
index e831ee4..b30d6fb 100644
@@ -43,7 +43,7 @@
  */
 static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
 				     struct audioformat *fp,
-				     int format, void *_fmt,
+				     unsigned int format, void *_fmt,
 				     int protocol)
 {
 	int sample_width, sample_bytes;
@@ -353,7 +353,7 @@ err:
  * parse the format type I and III descriptors
  */
 static int parse_audio_format_i(struct snd_usb_audio *chip,
-				struct audioformat *fp, int format,
+				struct audioformat *fp, unsigned int format,
 				struct uac_format_type_i_continuous_descriptor *fmt,
 				struct usb_host_interface *iface)
 {
@@ -473,8 +473,9 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip,
 	return ret;
 }
 
-int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
-			       int format, struct uac_format_type_i_continuous_descriptor *fmt,
+int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
+			       struct audioformat *fp, unsigned int format,
+			       struct uac_format_type_i_continuous_descriptor *fmt,
 			       int stream, struct usb_host_interface *iface)
 {
 	int err;
sound/usb/format.h +1 -1
index 387924f..6f31522 100644
@@ -2,7 +2,7 @@
 #define __USBAUDIO_FORMAT_H
 
 int snd_usb_parse_audio_format(struct snd_usb_audio *chip,
-			       struct audioformat *fp, int format,
+			       struct audioformat *fp, unsigned int format,
 			       struct uac_format_type_i_continuous_descriptor *fmt,
 			       int stream, struct usb_host_interface *iface);
 
sound/usb/stream.c +1 -1
index ad181d5..ad07046 100644
@@ -463,7 +463,7 @@ int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
 	struct usb_host_interface *alts;
 	struct usb_interface_descriptor *altsd;
 	int i, altno, err, stream;
-	int format = 0, num_channels = 0;
+	unsigned int format = 0, num_channels = 0;
 	struct audioformat *fp = NULL;
 	int num, protocol, clock = 0;
 	struct uac_format_type_i_continuous_descriptor *fmt;
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 ALSA: snd-usb: handle raw data format of UAC2 devices

In reply to Daniel Mack

UAC2 compliant audio devices may announce the capability to transport raw audio data on their endpoints. Catch this and handle it as 'special' stream on the ALSA side.

---
 include/linux/usb/audio-v2.h |    2 ++
 sound/usb/format.c           |   11 +++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)
include/linux/usb/audio-v2.h +2 -0
index ed13053..c5f2158 100644
@@ -170,6 +170,8 @@ struct uac2_as_header_descriptor {
 	__u8 iChannelNames;
 } __attribute__((packed));
 
+#define UAC2_FORMAT_TYPE_I_RAW_DATA	(1 << 31)
+
 /* 4.10.1.2 Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
 
 struct uac2_iso_endpoint_descriptor {
sound/usb/format.c +7 -4
index b30d6fb..a695caf 100644
@@ -47,7 +47,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
 				     int protocol)
 {
 	int sample_width, sample_bytes;
-	u64 pcm_formats;
+	u64 pcm_formats = 0;
 
 	switch (protocol) {
 	case UAC_VERSION_1:
@@ -63,14 +63,17 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
 		struct uac_format_type_i_ext_descriptor *fmt = _fmt;
 		sample_width = fmt->bBitResolution;
 		sample_bytes = fmt->bSubslotSize;
+
+		if (format & UAC2_FORMAT_TYPE_I_RAW_DATA)
+			pcm_formats |= SNDRV_PCM_FMTBIT_SPECIAL;
+
 		format <<= 1;
 		break;
 	}
 	}
 
-	pcm_formats = 0;
-
-	if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) {
+	if ((pcm_formats == 0) &&
+	    (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
 		/* some devices don't define this correctly... */
 		snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
 			    chip->dev->devnum, fp->iface, fp->altsetting);
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/3 ALSA: snd-usb: add delay quirk for "Playback Design" products

In reply to Daniel Mack

"Playback Design" products need a 50ms delay after setting the USB interface.

---
 sound/usb/pcm.c |    7 +++++++
 1 file changed, 7 insertions(+)
sound/usb/pcm.c +7 -0
index f94397b..c263991 100644
@@ -350,6 +350,13 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
 				fmt->iface, fmt->altsetting);
 		subs->interface = fmt->iface;
 		subs->altset_idx = fmt->altset_idx;
+
+		/*
+		 * "Playback Design" products need a 50ms delay after setting the
+		 * USB interface.
+		 */
+		if (le16_to_cpu(dev->descriptor.idVendor) == 0x23ba)
+			mdelay(50);
 	}
 
 	subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
Signature · 1 line
1.7.10.4
Applied
#4 lore raw
In reply to Daniel Mack

At Sun, 17 Mar 2013 20:07:23 +0800,

Quoted 9 lines · Daniel Mack

Thanks to Andreas, I got my hands on a Playback Design MPD-3 and hacked up some small hanges necessary to make it fully work with snd-usb.

The device reports 0x80000000 in the bmFormats field of two of three of its alternate settings, which wrongly made the driver believe it's a usual PCM endpoint (actually due to a fix-up fallback). However, bit 31 of this mask in fact denotes 'raw data'.

Quoted 5 lines

The effect of this issue is that in addition to the first altsetting with a bit depth of 24, the driver exposed 8-bit and 16-bit native audio formats on the raw data endpoints, which do not work as expected.

Also, those devices need a 50ms delay after switching the USB interface.

Thanks, applied to for-next branch.

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

Takashi

Quoted 21 lines

Thanks,
Daniel

Daniel Mack (3):
ALSA: snd-usb: handle the bmFormats field as unsigned int
ALSA: snd-usb: handle raw data format of UAC2 devices
ALSA: snd-usb: add delay quirk for "Playback Design" products

 include/linux/usb/audio-v2.h |    2 ++
 sound/usb/format.c           |   20 ++++++++++++--------
 sound/usb/format.h           |    2 +-
 sound/usb/pcm.c              |    7 +++++++
 sound/usb/stream.c           |    2 +-
 5 files changed, 23 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.10.4
#5 lore raw
Quoted 15 lines · Takashi Iwai

At Sun, 17 Mar 2013 20:07:23 +0800,

Quoted 13 lines · Daniel Mack

Thanks to Andreas, I got my hands on a Playback Design MPD-3 and hacked up some small hanges necessary to make it fully work with snd-usb.

The device reports 0x80000000 in the bmFormats field of two of three of its alternate settings, which wrongly made the driver believe it's a usual PCM endpoint (actually due to a fix-up fallback). However, bit 31 of this mask in fact denotes 'raw data'.

The effect of this issue is that in addition to the first altsetting with a bit depth of 24, the driver exposed 8-bit and 16-bit native audio formats on the raw data endpoints, which do not work as expected.

Quoted 7 lines
Quoted 1 line

Also, those devices need a 50ms delay after switching the USB interface.

Thanks, applied to for-next branch.

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

Yes, I thought about that for a while as well. In fact, the data format the device supports on these altsettings is "DSD", but that doesn't have a defined value in the UAC2 spec (and strictly speaking, DSD is not even PCM).

So when a device is as unspecific as 'raw data', there's not much we can do about that except for exposing the same level of uncertainty down to the apps, right?

Thanks,
Daniel

#6 lore raw

At Mon, 18 Mar 2013 10:15:44 +0100,

Quoted 25 lines · Daniel Mack
Quoted 15 lines · Takashi Iwai

At Sun, 17 Mar 2013 20:07:23 +0800,

Quoted 13 lines · Daniel Mack

Thanks to Andreas, I got my hands on a Playback Design MPD-3 and hacked up some small hanges necessary to make it fully work with snd-usb.

The device reports 0x80000000 in the bmFormats field of two of three of its alternate settings, which wrongly made the driver believe it's a usual PCM endpoint (actually due to a fix-up fallback). However, bit 31 of this mask in fact denotes 'raw data'.

The effect of this issue is that in addition to the first altsetting with a bit depth of 24, the driver exposed 8-bit and 16-bit native audio formats on the raw data endpoints, which do not work as expected.

Quoted 7 lines
Quoted 1 line

Also, those devices need a 50ms delay after switching the USB interface.

Thanks, applied to for-next branch.

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

Quoted 8 lines

Yes, I thought about that for a while as well. In fact, the data format the device supports on these altsettings is "DSD", but that doesn't have a defined value in the UAC2 spec (and strictly speaking, DSD is not even PCM).

So when a device is as unspecific as 'raw data', there's not much we can do about that except for exposing the same level of uncertainty down to the apps, right?

Yes. We can add a new format SND_PCM_FORMAT_RAW, but it's not much better than SND_PCM_FORMAT_SPECIAL after all :)

Takashi

#7 lore raw
Quoted 32 lines · Takashi Iwai

At Mon, 18 Mar 2013 10:15:44 +0100,

Quoted 30 lines · Daniel Mack
Quoted 15 lines · Takashi Iwai

At Sun, 17 Mar 2013 20:07:23 +0800,

Quoted 13 lines · Daniel Mack

Thanks to Andreas, I got my hands on a Playback Design MPD-3 and hacked up some small hanges necessary to make it fully work with snd-usb.

The device reports 0x80000000 in the bmFormats field of two of three of its alternate settings, which wrongly made the driver believe it's a usual PCM endpoint (actually due to a fix-up fallback). However, bit 31 of this mask in fact denotes 'raw data'.

The effect of this issue is that in addition to the first altsetting with a bit depth of 24, the driver exposed 8-bit and 16-bit native audio formats on the raw data endpoints, which do not work as expected.

Quoted 7 lines
Quoted 1 line

Also, those devices need a 50ms delay after switching the USB interface.

Thanks, applied to for-next branch.

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

Yes, I thought about that for a while as well. In fact, the data format the device supports on these altsettings is "DSD", but that doesn't have a defined value in the UAC2 spec (and strictly speaking, DSD is not even PCM).

Quoted 6 lines
Quoted 3 lines

So when a device is as unspecific as 'raw data', there's not much we can do about that except for exposing the same level of uncertainty down to the apps, right?

Yes. We can add a new format SND_PCM_FORMAT_RAW, but it's not much better than SND_PCM_FORMAT_SPECIAL after all :)

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

Thanks,
Daniel

#39 lore raw
In reply to Takashi Iwai
Quoted 4 lines · Takashi Iwai

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

I got the impression that SND_PCM_FORMAT_SPECIAL was there for appication-specific/device-specific hacks. I.e. it's a non-format that allows passing raw data through the system. If so, is it appropriate for a main-line driver?

-gabriel

#8 lore raw
In reply to Daniel Mack
Quoted 9 lines · Daniel Mack
Quoted 9 lines
Quoted 8 lines

Yes, I thought about that for a while as well. In fact, the data format the device supports on these altsettings is "DSD", but that doesn't have a defined value in the UAC2 spec (and strictly speaking, DSD is not even PCM).

So when a device is as unspecific as 'raw data', there's not much we can do about that except for exposing the same level of uncertainty down to the apps, right?

Quoted 6 lines
Quoted 2 lines

Yes. We can add a new format SND_PCM_FORMAT_RAW, but it's not much better than SND_PCM_FORMAT_SPECIAL after all :)

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

+1

However, more and more applications are wanting to send non-linear PCM data through ALSA. So, we probably /do/ need to care.

-gabriel

#9 lore raw

At Mon, 18 Mar 2013 19:51:09 -0700,

Quoted 14 lines · Gabriel M. Beddingfield
Quoted 12 lines · Daniel Mack
Quoted 11 lines
Quoted 8 lines

Yes, I thought about that for a while as well. In fact, the data format the device supports on these altsettings is "DSD", but that doesn't have a defined value in the UAC2 spec (and strictly speaking, DSD is not even PCM).

So when a device is as unspecific as 'raw data', there's not much we can do about that except for exposing the same level of uncertainty down to the apps, right?

Yes. We can add a new format SND_PCM_FORMAT_RAW, but it's not much better than SND_PCM_FORMAT_SPECIAL after all :)

Quoted 8 lines
Quoted 3 lines

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

+1

However, more and more applications are wanting to send non-linear PCM data through ALSA. So, we probably /do/ need to care.

It depends. DSD would be still likely feasible to be sent over a PCM device, as it's an audio stream after all, but most of other non-audio data wouldn't fit with the "PCM" device.

Takashi

#40 lore raw
In reply to Gabriel M. Beddingfield

At Mon, 18 Mar 2013 19:37:51 -0700,

Quoted 11 lines · Gabriel M. Beddingfield
Quoted 4 lines · Takashi Iwai

The remaining question is which PCM format is suitable for the raw data. SND_PCM_FORMAT_SPECIAL should be OK, it won't regress at least, as no apps support this format.

I got the impression that SND_PCM_FORMAT_SPECIAL was there for appication-specific/device-specific hacks. I.e. it's a non-format that allows passing raw data through the system. If so, is it appropriate for a main-line driver?

It allows everything, but it also means there is no specification.

Takashi

#10 lore raw
In reply to Daniel Mack
Quoted 3 lines · Daniel Mack

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

Yes there is? At least my application. And I'd be happy to support any custom format created for the purpose... :)

(http://www.signalyst.com/consumer.html for those who are interested)

I would propose to create custom 8-bit sample formats for DSD purposes, similar to the ASIO formats. Practically two main ones, byte with oldest bit in MSB and byte with oldest bit in LSB. And maybe the "DSD-wide" one which is 8-bit DSD sample.

- Jussi

#11 lore raw

Hi Jussi,
Hi Andreas,

Quoted 7 lines · Jussi Laako
Quoted 3 lines · Daniel Mack

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

Yes there is? At least my application. And I'd be happy to support any custom format created for the purpose... :)

Ah, interesting. So what *are* you using right now for your transport in userspace? Is your application abusing standard PCM interfaces that are 'known' to be in fact DSD? How do other DACs expose their interfaces in the Linux world, and which ones did you test your application with?

If there's actual need for a new SND_PCM_FORMAT, it would be easy to patch it through all the layers down to userspace.

Quoted 4 lines

I would propose to create custom 8-bit sample formats for DSD purposes, similar to the ASIO formats. Practically two main ones, byte with oldest bit in MSB and byte with oldest bit in LSB. And maybe the "DSD-wide" one which is 8-bit DSD sample.

Andreas, which modes does the MPD-3 accept exactly on its two 'raw data' interfaces? The only hint I have is that one of it is 8-bit and the other is 16-bit, but given the lack of a proper test setup for this format, I can't currently test anything.

Thanks,
Daniel

#36 lore raw
In reply to a message not in the archive
Quoted 3 lines · Andreas Koch

I wouldn't worry about DSD wide, because that is a dead format that I was involved in launching for professional recording applications more than 10 years ago. It never took off.

I just need it for my own purposes, but I can make custom stuff as necessary if there's no interest from others.

Right now I'm just hoping to see a well defined common sample formats defined for ALSA that can be utilized by drivers. DoP could be implemented inside the driver or at ALSA layer instead of applications doing it. Not that I would mind, but I would find it cleaner than the current approach... :)

Currently, ASIO is the only API to support DSD sample formats. I understand that Microsoft or Apple is a slow to turn giant, but I'd hope ALSA wouldn't be such. ;)

There are already those IEC958 and DD/dts things being used for movie playback, so this wouldn't be such a big difference afterall.

- Jussi

#37 lore raw

At Fri, 22 Mar 2013 12:15:16 +0200,

Quoted 15 lines · Jussi Laako
Quoted 3 lines · Andreas Koch

I wouldn't worry about DSD wide, because that is a dead format that I was involved in launching for professional recording applications more than 10 years ago. It never took off.

I just need it for my own purposes, but I can make custom stuff as necessary if there's no interest from others.

Right now I'm just hoping to see a well defined common sample formats defined for ALSA that can be utilized by drivers. DoP could be implemented inside the driver or at ALSA layer instead of applications doing it. Not that I would mind, but I would find it cleaner than the current approach... :)

Quoted 3 lines

Currently, ASIO is the only API to support DSD sample formats. I understand that Microsoft or Apple is a slow to turn giant, but I'd hope ALSA wouldn't be such. ;)

As Daniel already mentioned, adding a format type is trivial. It needs to be patched in different layers, though. But, the action is easy.

More important question is how consistent the format is. If it's a device-specific closed format, it's not suitable as a standard format definition in the API level.

Quoted 2 lines

There are already those IEC958 and DD/dts things being used for movie playback, so this wouldn't be such a big difference afterall.

IEC958 itself is a well-defined format as a container. So we actually have no definition for DD/DTS in the ALSA API level at all.

Takashi

#38 lore raw
Quoted 3 lines · Takashi Iwai

More important question is how consistent the format is. If it's a device-specific closed format, it's not suitable as a standard format definition in the API level.

At least the ASIO way of two uint8_t based MSB/LSB formats is pretty much the standard common denominator. Rest of the possibly needed data arrangement can be handled by the driver.

For the DoP output it is already defined by Andreas:
http://dsd-guide.com/dop-open-standard

Which corresponds to the uint8_t with oldest bit in MSB. I'm now doing the packing for both packing styles in the application before sending it through ALSA. However, it would be cleaner for application to send uint8_t packets and handle the packing at driver level. Those pieces of custom USB hardware that don't use DoP but send raw DSD stream usually use either uint8_t or uint32_t containers. So the uint8_t is the lowest common denominator. So we wouldn't need to worry about the byte order in addition to bit order...

- Jussi

#12 lore raw
In reply to Daniel Mack
Quoted 4 lines · Daniel Mack

Ah, interesting. So what *are* you using right now for your transport in userspace? Is your application abusing standard PCM interfaces that are 'known' to be in fact DSD? How do other DACs expose their interfaces in the Linux world, and which ones did you test your application with?

Yes, it's abuse of PCM (hw) interface, I'm using the DoP specification as referred to in another post. All the DSD DACs that currently work with Linux support this. Quite many at the moment in fact and more coming all the time.

There's at least devices from Mytek, Fostex, Benchmark and Sonore/exD that work with this setup. And I believe also Chord, but I haven't got chance to test it yet.

Mytek has a vendor specific interface (RigiSystems USBPAL) that could utilize a separate raw DSD sample format.

Plus I have some of my own experiments implementing DSD on an ARM based SoC where there's no need use DoP, but now I need to use custom hack for the raw data. Thus sooner there's some officially defined ALSA formats, less likely it becomes fragmented set of different incompatible hacks. That would be a headache and nightmare for application developers.

- Jussi

#13 lore raw

Support for DSD streams (was: Re: [PATCH 0/3] ALSA: snd-usb: Some small fixes to make Playback Design products work)

Hi Jussi,

Quoted 8 lines · Jussi Laako
Quoted 4 lines · Daniel Mack

Ah, interesting. So what *are* you using right now for your transport in userspace? Is your application abusing standard PCM interfaces that are 'known' to be in fact DSD? How do other DACs expose their interfaces in the Linux world, and which ones did you test your application with?

Yes, it's abuse of PCM (hw) interface, I'm using the DoP specification as referred to in another post.

It's really new to me that there are active users for this sample format, and we should clean up the mess by cleanly marking such streams correctly in the drivers. But I'm still not sure about the current situation in terms of hardware support. So let's shed some light ...

Quoted 3 lines

All the DSD DACs that currently work
with Linux support this. Quite many at the moment in fact and more coming all the time.

Ok, but how do you know about which interfaces are capable of handling that? Are you maintaining a white list?

And does that mean these devices are also wrongly believed to have additional PCM interfaces? IOW: do they only work as DSD, breaking all applications that believe that they can use all devices that expose a PCM interface?

Can you show the contents of /proc/asound/cardX/stream0 for such a card maybe?

Quoted 3 lines

There's at least devices from Mytek, Fostex, Benchmark and Sonore/exD that work with this setup. And I believe also Chord, but I haven't got chance to test it yet.

Can you provide the output of "lsusb -v" for any of these?

Quoted 8 lines

Mytek has a vendor specific interface (RigiSystems USBPAL) that could utilize a separate raw DSD sample format.

Plus I have some of my own experiments implementing DSD on an ARM based SoC where there's no need use DoP, but now I need to use custom hack for the raw data. Thus sooner there's some officially defined ALSA formats, less likely it becomes fragmented set of different incompatible hacks. That would be a headache and nightmare for application developers.

I'm afraid that adding a DSD format and teaching the driver quirks for interfaces that are known to support DSD would break applications that already expect to see a usual PCM interface.

To be precise: which SND_PCM_FORMAT_* does your application accept, and what happens if it sees SND_PCM_FORMAT_SPECIAL?

As for the driver, I would not go any further than marking the streams as DSD, without touching the payload. The marker bytes as described in the DoP document could be handled by some sort of libasound convenience function maybe though.

Daniel

#16 lore raw

Support for DSD streams (was: Re: [PATCH 0/3] ALSA: snd-usb: Some small fixes to make Playback Design products work)

In reply to a message not in the archive

Hi Andreas,

Quoted 31 lines · Andreas Koch
Quoted 25 lines · Daniel Mack

Hi Jussi,
Hi Andreas,

Quoted 7 lines · Jussi Laako
Quoted 3 lines · Daniel Mack

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

Yes there is? At least my application. And I'd be happy to support any custom format created for the purpose... :)

Ah, interesting. So what *are* you using right now for your transport in userspace? Is your application abusing standard PCM interfaces that are 'known' to be in fact DSD? How do other DACs expose their interfaces in the Linux world, and which ones did you test your application with?

If there's actual need for a new SND_PCM_FORMAT, it would be easy to patch it through all the layers down to userspace.

Quoted 4 lines

I would propose to create custom 8-bit sample formats for DSD purposes, similar to the ASIO formats. Practically two main ones, byte with oldest bit in MSB and byte with oldest bit in LSB. And maybe the "DSD-wide" one which is 8-bit DSD sample.

Quoted 4 lines

Andreas, which modes does the MPD-3 accept exactly on its two 'raw data' interfaces? The only hint I have is that one of it is 8-bit and the other is 16-bit, but given the lack of a proper test setup for this format, I can't currently test anything.

Quoted 4 lines

The 8-bit raw format is for 2.8MHz DSD and the 16-bit format is for 5.6MHz DSD. In both cases the driver sets the sample rate to 352.8kHz on the DAC, but then sends either 8 bits or 16 bits depending on the DSD rate.

And prior to sending either 8 bits or 16 bits, currently the correct USB alternate interface has to be set, right?

Quoted 3 lines

Since 11.2MHz DSD is already on the horizon we may have to change this to a single 8-bit raw interface and then vary the underlying USB transfer sample rate between 1x, 2x, 4x 352.8kHz -

Yes, especially given that if there's no common standard across different devices, either the drivers or the applications have to implement special handling code for this, and know which interface supports what.

So for the ALSA layer, we should probably have a generic SND_PCM_FORMAT_DSD and then rely on the sample rate setting mechanisms to select the right DSD mode. Other solutions, like having a different SND_PCM_FORMAT_DSD_{2_8,5_6,11_2}_MHZ would be hairy to implement, as some devices need to get a sample rate update request, while others don't etc ...

Quoted 8 lines

that would be more logical and straight forward for the hardware implementation. This is only supported through my own driver for the Windows platform which uses the standard ASIO interface that supports DSD at those rates. Since the Mac OS only supports PCM streams and nothing else I brought together a bunch of DAC manufacturers and playback software developers to standardize a method to "cannibalize" the PCM stream for DSD data. The method is described in the attached and is now supported by most manufacturers.

Very interesting read. For ALSA though, it's no problem to support that in all layers and make the drivers tell applications about it. We just have to decide for a sane way :)

Quoted 3 lines

This also has been implemented on a few Linux platforms (Auraliti for instance). Even though the DoP standard works really well so far, it is a "bandaid" and should only be used if there is no other choice.

Yes, understood. The thing is just that we shouldn't break exising solutions that already rely on this "bandaid".

Daniel

#18 lore raw

Re: Support for DSD streams

In reply to a message not in the archive

Hi Andreas,

Quoted 7 lines · Andreas Koch
Quoted 2 lines

Yes, understood. The thing is just that we shouldn't break exising solutions that already rely on this "bandaid".

You wouldn't break any existing solution based on DoP, because that solution is dealt with in the application on one side and the DAC on the other side. The driver and USB transfer both think it is PCM data that is being sent.

Well, that was exactly the problem with your device. With the driver as it was, it exposed a PCM interface which is 16-bit wide, and that was picked by ALSA when playing 16-bit material (because ALSA takes whatever is offered by the hardware natively).

Quoted 4 lines

The applications have a preference setting to
select DoP and likewise the DAC's constantly monitor the PCM formatted data stream and automatically switch to DSD if they find the pattern.

Hmm, but your device behaves differently here, right? At least, when normal PCM material is sent to the DSD interface, it doesn't play it or switch back or something. And I think other DACs will have similar behaviour.

I need to think about all that more deeply next week :)

Daniel

#14 lore raw

Re: Support for DSD streams

In reply to Daniel Mack

Hi Daniel,

Quoted 2 lines · Daniel Mack

Ok, but how do you know about which interfaces are capable of handling that? Are you maintaining a white list?

It's all up to user configuration, just an option in GUI for it. There are still some devices where the support depends on firmware version (support was introduced as firmware upgrade) so white listing is not so feasible always. But the situation is getting better. However I don't want to maintain a white list of vendor/device id's inside my application. Also the same format works over S/PDIF or AES/EBU just fine (with dual-wire up to DSD128). So automatic detection is not always possible anyway.

However I'm hoping to get the relevant information through the audio API in future for all possible interfaces (IOW not S/PDIF or AES/EBU, but things like USB, Firewire, PCI(e) and ASoC). Since there many DAC chips that have support for DSD it makes sense.

Quoted 4 lines

And does that mean these devices are also wrongly believed to have additional PCM interfaces? IOW: do they only work as DSD, breaking all applications that believe that they can use all devices that expose a PCM interface?

So far all devices have been supporting also PCM, but support for DSD128 is already a problem. Since with DoP it would require 352.8k PCM sample rate support, but some devices can do PCM only up to 192 while being able to support DSD128. Currently there's no way to figure out such limitations through ALSA (unlike ASIO where sampling rate enumeration is completely separate for PCM and DSD). So application would assume that also 352.8 PCM is available.

Quoted 3 lines

Can you show the contents of /proc/asound/cardX/stream0 for such a card maybe?
Can you provide the output of "lsusb -v" for any of these?

There's nothing related to DSD there, because DoP is implemented in an FPGA behind the audio interface. Most common is the XMOS UAC2 implementation. Just normal asynchronous UAC2.

For the rest it's device class "vendor specific".

Quoted 3 lines

I'm afraid that adding a DSD format and teaching the driver quirks for interfaces that are known to support DSD would break applications that already expect to see a usual PCM interface.

Currently most interfaces support usual PCM, but in addition they support also DSD. So they have two native sample formats, but only one USB format. Except again the vendor specific ones where there tend to be two wire formats, like 3-byte 24-bit and byte stream for DSD.

Quoted 2 lines

To be precise: which SND_PCM_FORMAT_* does your application accept, and what happens if it sees SND_PCM_FORMAT_SPECIAL?

For PCM:

        SND_PCM_FORMAT_S16_LE
        SND_PCM_FORMAT_S16_BE
        SND_PCM_FORMAT_S24_LE
        SND_PCM_FORMAT_S24_BE
        SND_PCM_FORMAT_S32_LE
        SND_PCM_FORMAT_S32_BE
        SND_PCM_FORMAT_S18_3LE
        SND_PCM_FORMAT_S20_3LE
        SND_PCM_FORMAT_S24_3LE
        SND_PCM_FORMAT_S18_3BE
        SND_PCM_FORMAT_S20_3BE
        SND_PCM_FORMAT_S24_3BE
        SND_PCM_FORMAT_FLOAT_LE
        SND_PCM_FORMAT_FLOAT_BE
        SND_PCM_FORMAT_FLOAT64_LE
        SND_PCM_FORMAT_FLOAT64_BE

For DSD:

        SND_PCM_FORMAT_S8
        SND_PCM_FORMAT_U8
        SND_PCM_FORMAT_S24_LE
        SND_PCM_FORMAT_U24_LE
        SND_PCM_FORMAT_S24_BE
        SND_PCM_FORMAT_U24_BE
        SND_PCM_FORMAT_S32_LE
        SND_PCM_FORMAT_U32_LE
        SND_PCM_FORMAT_S32_BE
        SND_PCM_FORMAT_U32_BE
        SND_PCM_FORMAT_S24_3LE
        SND_PCM_FORMAT_U24_3LE
        SND_PCM_FORMAT_S24_3BE
        SND_PCM_FORMAT_U24_3BE

I'm currently using SND_PCM_FORMAT_U8 at 352800 for my raw DSD custom hacks, because it won't overlap with any real world PCM hardware... For DoP devices there are at least SND_PCM_FORMAT_S32_LE and SND_PCM_FORMAT_S24_3LE in use. XMOS uses the former one, IIRC Mytek with the TCAT Dice FW chipset uses the latter one (and the USB2 is vendor specific class).

I don't support SND_PCM_FORMAT_SPECIAL.

Quoted 4 lines

As for the driver, I would not go any further than marking the streams as DSD, without touching the payload. The marker bytes as described in the DoP document could be handled by some sort of libasound convenience function maybe though.

OK, then I would most likely keep the payload packing as it is already...

- Jussi

#21 lore raw
In reply to a message not in the archive
Quoted 3 lines · Andreas Koch

The 8-bit raw format is for 2.8MHz DSD and the 16-bit format is for 5.6MHz DSD. In both cases the driver sets the sample rate to 352.8kHz on the DAC,

I see, this is different from how I've been dealing with it. Since I always use uint8 format, but instead vary the rate to 352.8/705.6/etc...

Just because it's much more straightforward form the application's perspective -> output rate is always bit rate divided by eight (=packet rate). And switch between uint8 / uint32 sample format equals to switch between DSD <-> PCM.

- Jussi

#23 lore raw
In reply to a message not in the archive
Quoted 4 lines · Andreas Koch

rate for PCM. If you plug that DAC into a Mac, the Mac will automatically select 705.6kHz for PCM and then nothing will work because the DAC doesn't support that in PCM. So then, the DAC would have to define 2 complete interfaces: one for PCM and one for DSD. That

OK, the difference is that I don't use UAC2 at all, but completely different protocol. So what I'm talking about is only how it looks from the driver towards the application...

DoP could be implemented similar way inside the UAC driver using for example snd_pcm_hw_rule_add() between SNDRV_PCM_HW_PARAM_FORMAT and SNDRV_PCM_HW_PARAM_RATE. And maybe enabled as quirks?

There are many devices having constraints between rate and channels. In this case we just have a constraint between rate and formats.

Looking at the UAC driver there seems to be something a bit related:

                /* FIXME: there is no AC3 format defined yet */
                // fp->formats = SNDRV_PCM_FMTBIT_AC3;
                fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to 

receive
byte streams */

- Jussi

#24 lore raw
Quoted 9 lines · Jussi Laako
Quoted 4 lines · Andreas Koch

rate for PCM. If you plug that DAC into a Mac, the Mac will automatically select 705.6kHz for PCM and then nothing will work because the DAC doesn't support that in PCM. So then, the DAC would have to define 2 complete interfaces: one for PCM and one for DSD. That

OK, the difference is that I don't use UAC2 at all, but completely different protocol. So what I'm talking about is only how it looks from the driver towards the application...

What protocol is that? Is there a driver for Linux?

Daniel

#26 lore raw
In reply to a message not in the archive

Hi Andreas,

Quoted 14 lines · Andreas Koch
Quoted 5 lines · Jussi Laako
Quoted 3 lines · Andreas Koch

The 8-bit raw format is for 2.8MHz DSD and the 16-bit format is for 5.6MHz DSD. In both cases the driver sets the sample rate to 352.8kHz on the DAC,

Quoted 7 lines

I see, this is different from how I've been dealing with it. Since I always use uint8 format, but instead vary the rate to 352.8/705.6/etc...

Just because it's much more straightforward form the application's perspective -> output rate is always bit rate divided by eight (=packet rate). And switch between uint8 / uint32 sample format equals to switch between DSD <-> PCM.

Quoted 14 lines

Since the sample rate is defined on the interface level, not on the alternate interface level, it becomes a problem to vary the sample rate. For instance, for 5.6MHz DSD a sample rate of 705.6kHz would be necessary with 8-bit data. But most likely the DAC will not support that rate for PCM. If you plug that DAC into a Mac, the Mac will automatically select 705.6kHz for PCM and then nothing will work because the DAC doesn't support that in PCM. So then, the DAC would have to define 2 complete interfaces: one for PCM and one for DSD. That increases the size of the descriptor file (which can be a problem with some hardware implementations) and increases the overhead a bit during enumeration and sample rate queries. For the hardware it is easier to bundle all into one single interface and then define alternate interfaces for PCM and DSD.
Just my 2 cents from the hardware perspective.

Ok. So we could define 3 DSD formats, for 8-bit, 16-bit and 32-bit. On that three formats, arbitrary samples can be transported, and the mapping between the configured sample rate and the resulting DSD rates would be as follows (please tell me if I'm correct):

        352.8kHz       705.6KHz    1411.2KHz

8-bit 2.8MHz 5.6MHz 11.2MHz
16-bit 5.6MHz 11.2MHz
32-bit 11.2MHz

So driver would mark a stream as DSD capable (8, 16, 32bit, depending on the USB descriptors), and then leave it up to the application to do the sample frequency determination according to the above table, and also as stated in the DoP document. Other drivers for more sound cards (presumable on other bus types) might follow.

I think it's ok to handle it like this, because after all, what an application sets as sample rate for the stream is the number of actual words that are transported, where as the DSD rate is referring to bits/s.

Jussi, for your application, that means that you'd have to add these 3 new formats, and teach your application that they can be used for DSD right away.

The question is whether all DSD-capable USB DACs behave correctly in order to make this logic work. Andreas?

Thanks,
Daniel

#28 lore raw
In reply to a message not in the archive
Quoted 3 lines · Andreas Koch

... your driver would send the DSD data in whatever format the DAC requests via its descriptors. [...] The only potential fly in the ointment is that we assume that the raw data format means DSD.

Add some vendor-specific descriptor to specify that raw means DSD.

Regards,
Clemens

#29 lore raw
In reply to a message not in the archive
Quoted 30 lines · Andreas Koch

Hi Daniel

Quoted 21 lines

Ok. So we could define 3 DSD formats, for 8-bit, 16-bit and 32-bit. On that three formats, arbitrary samples can be transported, and the mapping between the configured sample rate and the resulting DSD rates would be as follows (please tell me if I'm correct):

        352.8kHz       705.6KHz    1411.2KHz

8-bit 2.8MHz 5.6MHz 11.2MHz
16-bit 5.6MHz 11.2MHz
32-bit 11.2MHz

So driver would mark a stream as DSD capable (8, 16, 32bit, depending on the USB descriptors), and then leave it up to the application to do the sample frequency determination according to the above table, and also as stated in the DoP document. Other drivers for more sound cards (presumable on other bus types) might follow.

I think it's ok to handle it like this, because after all, what an application sets as sample rate for the stream is the number of actual words that are transported, where as the DSD rate is referring to bits/s.

Quoted 6 lines

Jussi, for your application, that means that you'd have to add these 3 new formats, and teach your application that they can be used for DSD right away.

The question is whether all DSD-capable USB DACs behave correctly in order to make this logic work. Andreas?

Quoted 6 lines

If I understand this correctly then your driver would send the DSD data in whatever format the DAC requests via its descriptors. The DSD rate would either control the word length (8,16,32) or the underlying sample rate (1x, 2x, 4x 352.8kHz). That would be the most flexible implementation and I don't see why any hardware implementation would have a problem with that.

The question is whether all DACs would assume the same DSD rate as in the table above (ie, 8-bit, 352.8kHz == 2.8MHz DSD).

And do we actually need a 32-bit format at all or is 8 and 16 enough?

Quoted 5 lines

The only potential fly in the ointment is
that we assume that the raw data format means DSD. In other words, if a DAC uses raw data for any other purpose with similar wordlength and/or sample rate spec. then we are in trouble. The chance for that is small though.

As there's nothing the UAC2 spec helps us with, we have to live with quirks for that.

Daniel

#20 lore raw

Re: Support for DSD streams

In reply to a message not in the archive
Quoted 14 lines · Andreas Koch

Hi Daniel,

Quoted 11 lines · Daniel Mack

Hi Andreas,

Quoted 7 lines · Andreas Koch
Quoted 2 lines

Yes, understood. The thing is just that we shouldn't break exising solutions that already rely on this "bandaid".

You wouldn't break any existing solution based on DoP, because that solution is dealt with in the application on one side and the DAC on the other side. The driver and USB transfer both think it is PCM data that is being sent.

Quoted 7 lines
Quoted 4 lines

Well, that was exactly the problem with your device. With the driver as it was, it exposed a PCM interface which is 16-bit wide, and that was picked by ALSA when playing 16-bit material (because ALSA takes whatever is offered by the hardware natively).

Not quite - the 16-bit wide interface offered by my DAC is not PCM, but raw data.

For the correct quirks handling, I'd need to know whether all products with your vendor ID are DSD capable on alt interface settings > 1. Is that assumption correct or should I narrow it down to the product ID of the MPD-3?

Thanks,
Daniel

#31 lore raw
In reply to a message not in the archive
Quoted 39 lines · Andreas Koch
Quoted 38 lines · Daniel Mack
Quoted 36 lines · Andreas Koch

Hi Daniel

Quoted 21 lines

Ok. So we could define 3 DSD formats, for 8-bit, 16-bit and 32-bit. On that three formats, arbitrary samples can be transported, and the mapping between the configured sample rate and the resulting DSD rates would be as follows (please tell me if I'm correct):

        352.8kHz       705.6KHz    1411.2KHz

8-bit 2.8MHz 5.6MHz 11.2MHz
16-bit 5.6MHz 11.2MHz
32-bit 11.2MHz

So driver would mark a stream as DSD capable (8, 16, 32bit, depending on the USB descriptors), and then leave it up to the application to do the sample frequency determination according to the above table, and also as stated in the DoP document. Other drivers for more sound cards (presumable on other bus types) might follow.

I think it's ok to handle it like this, because after all, what an application sets as sample rate for the stream is the number of actual words that are transported, where as the DSD rate is referring to bits/s.

Quoted 6 lines

Jussi, for your application, that means that you'd have to add these 3 new formats, and teach your application that they can be used for DSD right away.

The question is whether all DSD-capable USB DACs behave correctly in order to make this logic work. Andreas?

If I understand this correctly then your driver would send the DSD data in whatever format the DAC requests via its descriptors. The DSD rate would either control the word length (8,16,32) or the underlying sample rate (1x, 2x, 4x 352.8kHz). That would be the most flexible implementation and I don't see why any hardware implementation would have a problem with that.

Quoted 5 lines
Quoted 2 lines

The question is whether all DACs would assume the same DSD rate as in the table above (ie, 8-bit, 352.8kHz == 2.8MHz DSD).

I don't see how they could assume any different rate, so yes, that seems a good assumption.

Ok, good.

Quoted 8 lines
Quoted 1 line

And do we actually need a 32-bit format at all or is 8 and 16 enough?

Clearly, main stream is 2.8MHz DSD. But there are new A/D and D/A chips becoming available that support up to 11.2MHz. So far I haven't really seen any performance gain with that, but one never knows what improvements will be made in the future. If that is a problem on your side I wouldn't spend so much time on it, but if it is a matter of just adding a few lines then why not.

It a bit in a 64bit field, so its a limited resource. If there's no need for it, I'll leave it out for now.

I'll send out some trivial patches for DSD stream marking soon.

Thanks,
Daniel

#34 lore raw
In reply to a message not in the archive
Quoted 44 lines · Andreas Koch

Hi all,

Quoted 25 lines · Daniel Mack

Hi Jussi,
Hi Andreas,

Quoted 7 lines · Jussi Laako
Quoted 3 lines · Daniel Mack

Yes. If at all, we should add a SND_PCM_FORMAT_DSD, and a quirk for that device. But given that there is no application for DSD in userspace either, we probably don't need to care.

Yes there is? At least my application. And I'd be happy to support any custom format created for the purpose... :)

Ah, interesting. So what *are* you using right now for your transport in userspace? Is your application abusing standard PCM interfaces that are 'known' to be in fact DSD? How do other DACs expose their interfaces in the Linux world, and which ones did you test your application with?

If there's actual need for a new SND_PCM_FORMAT, it would be easy to patch it through all the layers down to userspace.

Quoted 4 lines

I would propose to create custom 8-bit sample formats for DSD purposes, similar to the ASIO formats. Practically two main ones, byte with oldest bit in MSB and byte with oldest bit in LSB. And maybe the "DSD-wide" one which is 8-bit DSD sample.

Quoted 4 lines

Andreas, which modes does the MPD-3 accept exactly on its two 'raw data' interfaces? The only hint I have is that one of it is 8-bit and the other is 16-bit, but given the lack of a proper test setup for this format, I can't currently test anything.

The 8-bit raw format is for 2.8MHz DSD and the 16-bit format is for 5.6MHz DSD. In both cases the driver sets the sample rate to 352.8kHz on the DAC, but then sends either 8 bits or 16 bits depending on the DSD rate. Since 11.2MHz DSD is already on the horizon we may have to change this to a single 8-bit raw interface and then vary the underlying USB transfer sample rate between 1x, 2x, 4x 352.8kHz - that would be more logical and straight forward for the hardware implementation. This is only supported through my own driver for the Windows platform which uses the standard ASIO interface that supports DSD at those rates. Since the Mac OS only supports PCM streams and nothing else I brought together a bunch of DAC manufacturers and

Quoted 8 lines

playback software developers to standardize a method to "cannibalize" the PCM stream for DSD data. The method is described in the attached and is now supported by most manufacturers.
This also has been implemented on a few Linux platforms (Auraliti for instance). Even though the DoP standard works really well so far, it is a "bandaid" and should only be used if there is no other choice. If you guys are discussing implementing a dedicated data stream in your driver for DSD, then I think this would be better and safer in the future.

Is there any official stable download location for this document which we could link to from our documentation?

Thanks,
Daniel

#32 lore raw
In reply to a message not in the archive
Quoted 2 lines · Andreas Koch

Clearly, main stream is 2.8MHz DSD. But there are new A/D and D/A chips becoming available that support up to 11.2MHz. So far I haven't really

And many DACs actually support also the 48k-base rates of 3.0/6.1/12.2 MHz. But of course from API point of view that's trivial.

- Jussi

#33 lore raw
In reply to Daniel Mack

Hi Daniel,

Quoted 3 lines · Daniel Mack

Jussi, for your application, that means that you'd have to add these 3 new formats, and teach your application that they can be used for DSD right away.

Looks good to me. This is what I was hoping for. I already kind of have the 8-bit and 32-bit, but I'll need to add the 16-bit one and make some related code cleanups to make things proper now since it's becoming official format.

I'll put this into my 3.0 release. :)

Thanks,

- Jussi

#25 lore raw
In reply to Daniel Mack
Quoted 1 line · Daniel Mack

What protocol is that? Is there a driver for Linux?

Just a custom flow-controlled bulk-mode byte stream. I have some hacks to make things work for my own prototype purposes, but I haven't got time to make anything clean and worth releasing.

There's not much point in releasing a driver that nobody else has hardware for... :)

I was hoping to discuss the ALSA sample format topic already earlier in context of getting DSD support to the RigiSystems USBPAL Linux driver, but it doesn't seem to be proceeding anywhere and I don't have necessary documentation (nor time)...
https://github.com/lintweaker/mytekusb2
I have the hardware though, so I can test & develop things at application side.

- Jussi