ALSA: snd-usb: add support for bit-reversed byte formats
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> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
d24f5061ee
commit
44dcbbb1cd
|
@ -29,6 +29,7 @@ struct audioformat {
|
||||||
unsigned char clock; /* associated clock */
|
unsigned char clock; /* associated clock */
|
||||||
struct snd_pcm_chmap_elem *chmap; /* (optional) channel map */
|
struct snd_pcm_chmap_elem *chmap; /* (optional) channel map */
|
||||||
bool dsd_dop; /* add DOP headers in case of DSD samples */
|
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;
|
struct snd_usb_substream;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/bitrev.h>
|
||||||
#include <linux/ratelimit.h>
|
#include <linux/ratelimit.h>
|
||||||
#include <linux/usb.h>
|
#include <linux/usb.h>
|
||||||
#include <linux/usb/audio.h>
|
#include <linux/usb/audio.h>
|
||||||
|
@ -1264,7 +1265,12 @@ static inline void fill_playback_urb_dsd_dop(struct snd_usb_substream *subs,
|
||||||
} else {
|
} else {
|
||||||
/* stuff the DSD payload */
|
/* stuff the DSD payload */
|
||||||
int idx = (src_idx + subs->dsd_dop.byte_idx - 1) % wrap;
|
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++;
|
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 &&
|
if (unlikely(subs->pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE &&
|
||||||
subs->cur_audiofmt->dsd_dop)) {
|
subs->cur_audiofmt->dsd_dop)) {
|
||||||
fill_playback_urb_dsd_dop(subs, urb, bytes);
|
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 {
|
} else {
|
||||||
/* usual PCM */
|
/* usual PCM */
|
||||||
if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
|
if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
|
||||||
|
|
Loading…
Reference in New Issue