aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-03-21 09:01:56 +0100
committerMax Kellermann <max@duempel.org>2012-03-21 09:01:56 +0100
commit238c3adad1724054b454f76857307e368e519585 (patch)
tree37c079eb8340211c9830fc2683d74899456a9e9f /src
parentc1d0a8b5ce93c4b70b00b14f2015fb6a57681dbe (diff)
decoder/dsdiff: reverse bits to most significant bit first
Allow to remove this complexity from the MPD core.
Diffstat (limited to 'src')
-rw-r--r--src/decoder/dsdiff_decoder_plugin.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/decoder/dsdiff_decoder_plugin.c b/src/decoder/dsdiff_decoder_plugin.c
index 751eff4d..ae42002d 100644
--- a/src/decoder/dsdiff_decoder_plugin.c
+++ b/src/decoder/dsdiff_decoder_plugin.c
@@ -28,6 +28,7 @@
#include "dsdiff_decoder_plugin.h"
#include "decoder_api.h"
#include "audio_check.h"
+#include "util/bit_reverse.h"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
@@ -54,14 +55,12 @@ struct dsdiff_metadata {
unsigned sample_rate, channels;
};
-static enum sample_format dsd_sample_format;
+static bool lsbitfirst;
static bool
dsdiff_init(const struct config_param *param)
{
- dsd_sample_format = config_get_block_bool(param, "lsbitfirst", false)
- ? SAMPLE_FORMAT_DSD_LSBFIRST
- : SAMPLE_FORMAT_DSD;
+ lsbitfirst = config_get_block_bool(param, "lsbitfirst", false);
return true;
}
@@ -301,6 +300,13 @@ dsdiff_read_metadata(struct decoder *decoder, struct input_stream *is,
}
}
+static void
+bit_reverse_buffer(uint8_t *p, uint8_t *end)
+{
+ for (; p < end; ++p)
+ *p = bit_reverse(*p);
+}
+
/**
* Decode one "DSD" chunk.
*/
@@ -332,6 +338,9 @@ dsdiff_decode_chunk(struct decoder *decoder, struct input_stream *is,
chunk_size -= nbytes;
+ if (lsbitfirst)
+ bit_reverse_buffer(buffer, buffer + nbytes);
+
enum decoder_command cmd =
decoder_data(decoder, is, buffer, nbytes, 0);
switch (cmd) {
@@ -367,7 +376,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
GError *error = NULL;
struct audio_format audio_format;
if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- dsd_sample_format,
+ SAMPLE_FORMAT_DSD,
metadata.channels, &error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -420,7 +429,7 @@ dsdiff_scan_stream(struct input_stream *is,
struct audio_format audio_format;
if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
- dsd_sample_format,
+ SAMPLE_FORMAT_DSD,
metadata.channels, NULL))
/* refuse to parse files which we cannot play anyway */
return false;