All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, clemens@ladisch.de, Daniel Mack <zonque@gmail.com>,
	demian@auraliti.com, ray@auraliti.com, andreas@akdesigninc.com
Subject: [PATCH v3 4/5] ALSA: snd-usb: add support for bit-reversed byte formats
Date: Wed, 17 Apr 2013 00:01:39 +0800	[thread overview]
Message-ID: <1366128100-9778-5-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1366128100-9778-1-git-send-email-zonque@gmail.com>

There is quite some confusion around the bit-ordering in DSD samples,
and no general agreement that defines whether hardware is supposed to
expect the oldest sample in the MSB or the LSB of a byte.

ALSA will hence set the rule that on the software API layer, bytes
always carry the oldest bit in the most significant bit of a byte, and
the driver has to translate that at runtime in order to match the
hardware layout.

This patch adds support for this by adding a boolean flag to the
audio format struct.

Signed-off-by: Daniel Mack <zonque@gmail.com>
---
 sound/usb/card.h |    1 +
 sound/usb/pcm.c  |   19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/sound/usb/card.h b/sound/usb/card.h
index 2c05cb7..fcae411 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -29,6 +29,7 @@ struct audioformat {
 	unsigned char clock;		/* associated clock */
 	struct snd_pcm_chmap_elem *chmap; /* (optional) channel map */
 	bool dsd_dop;			/* add DOP headers in case of DSD samples */
+	bool dsd_bitrev;		/* reverse the bits of each DSD sample */
 };
 
 struct snd_usb_substream;
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index b5eae93..c31980c 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -16,6 +16,7 @@
 
 #include <linux/init.h>
 #include <linux/slab.h>
+#include <linux/bitrev.h>
 #include <linux/ratelimit.h>
 #include <linux/usb.h>
 #include <linux/usb/audio.h>
@@ -1264,7 +1265,12 @@ static inline void fill_playback_urb_dsd_dop(struct snd_usb_substream *subs,
 		} else {
 			/* stuff the DSD payload */
 			int idx = (src_idx + subs->dsd_dop.byte_idx - 1) % wrap;
-			dst[dst_idx++] = src[idx];
+
+			if (subs->cur_audiofmt->dsd_bitrev)
+				dst[dst_idx++] = bitrev8(src[idx]);
+			else
+				dst[dst_idx++] = src[idx];
+
 			subs->hwptr_done++;
 		}
 	}
@@ -1330,6 +1336,17 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
 	if (unlikely(subs->pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE &&
 		     subs->cur_audiofmt->dsd_dop)) {
 		fill_playback_urb_dsd_dop(subs, urb, bytes);
+	} else if (unlikely(subs->pcm_format == SNDRV_PCM_FORMAT_DSD_U8 &&
+			   subs->cur_audiofmt->dsd_bitrev)) {
+		/* bit-reverse the bytes */
+		u8 *buf = urb->transfer_buffer;
+		for (i = 0; i < bytes; i++) {
+			int idx = (subs->hwptr_done + i)
+				% (runtime->buffer_size * stride);
+			buf[i] = bitrev8(runtime->dma_area[idx]);
+		}
+
+		subs->hwptr_done += bytes;
 	} else {
 		/* usual PCM */
 		if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
-- 
1.7.10.4

  parent reply	other threads:[~2013-04-16 16:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-16 16:01 [PATCH v3 0/5] ALSA: snd-usb: add support for DSD Daniel Mack
2013-04-16 16:01 ` [PATCH v3 1/5] ALSA: add DSD formats Daniel Mack
2013-04-16 16:01 ` [PATCH v3 2/5] ALSA: snd-usb: use ep->stride from urb callbacks Daniel Mack
2013-04-16 16:01 ` [PATCH v3 3/5] ALSA: snd-usb: add support for DSD DOP stream transport Daniel Mack
2013-04-16 16:01 ` Daniel Mack [this message]
2013-04-16 16:01 ` [PATCH v3 5/5] ALSA: snd-usb: add quirks handler for DSD streams Daniel Mack
2013-04-16 16:13 ` [PATCH v3 0/5] ALSA: snd-usb: add support for DSD Takashi Iwai
2013-04-17 10:59 ` Takashi Iwai
2013-04-17 11:03   ` Daniel Mack
2013-04-17 17:01     ` Jussi Laako
2013-04-17 17:04       ` Daniel Mack
2013-04-17 17:13         ` Jussi Laako
2013-04-18  8:05           ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1366128100-9778-5-git-send-email-zonque@gmail.com \
    --to=zonque@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andreas@akdesigninc.com \
    --cc=clemens@ladisch.de \
    --cc=demian@auraliti.com \
    --cc=ray@auraliti.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.