From cc0dbcf3f45a8ce6473c984f16e7bc3c68456ad7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 11 Jan 2017 22:25:54 +0100 Subject: [PATCH] pcm/Dsd32: fix the byte order The byte order of DSD_U32 was wrong from the start. The oldest bits must be in the MSB, not in the LSB, according to snd_pcm_format_descriptions in alsa-lib. --- NEWS | 1 + src/pcm/Dsd32.cxx | 7 +++++-- src/pcm/Dsd32.hxx | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 8ad91c3b1..a76b21218 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ ver 0.20.2 (not yet released) - libsamplerate: reset state after seeking * output - alsa: fix the DSD_U32 sample rate + - alsa: fix the DSD_U32 byte order ver 0.20.1 (2017/01/09) * input diff --git a/src/pcm/Dsd32.cxx b/src/pcm/Dsd32.cxx index 017774ff5..b8245f47c 100644 --- a/src/pcm/Dsd32.cxx +++ b/src/pcm/Dsd32.cxx @@ -29,8 +29,11 @@ static constexpr inline uint32_t Construct32(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { - return uint32_t(a) | (uint32_t(b) << 8) | - (uint32_t(c) << 16) | (uint32_t(d) << 24); + /* "a" is the oldest byte, which must be in the most + significant byte */ + + return uint32_t(d) | (uint32_t(c) << 8) | + (uint32_t(b) << 16) | (uint32_t(a) << 24); } static constexpr inline uint32_t diff --git a/src/pcm/Dsd32.hxx b/src/pcm/Dsd32.hxx index 30b1c8ee2..5f68814f4 100644 --- a/src/pcm/Dsd32.hxx +++ b/src/pcm/Dsd32.hxx @@ -28,7 +28,7 @@ template struct ConstBuffer; class PcmBuffer; /** - * Convert DSD_U8 to DSD_U32 (native endian). + * Convert DSD_U8 to DSD_U32 (native endian, oldest bits in MSB). */ ConstBuffer Dsd8To32(PcmBuffer &buffer, unsigned channels, ConstBuffer src);