From 238c3adad1724054b454f76857307e368e519585 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 21 Mar 2012 09:01:56 +0100 Subject: decoder/dsdiff: reverse bits to most significant bit first Allow to remove this complexity from the MPD core. --- Makefile.am | 3 +++ src/decoder/dsdiff_decoder_plugin.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index d7f7f2314..9936165c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1046,6 +1046,7 @@ test_dump_playlist_LDADD = \ $(GLIB_LIBS) test_dump_playlist_SOURCES = test/dump_playlist.c \ $(DECODER_SRC) \ + src/util/bit_reverse.c \ src/io_thread.c src/io_thread.h \ src/conf.c src/tokenizer.c src/utils.c src/string_util.c\ src/uri.c \ @@ -1072,6 +1073,7 @@ test_run_decoder_LDADD = \ $(GLIB_LIBS) test_run_decoder_SOURCES = test/run_decoder.c \ test/stdbin.h \ + src/util/bit_reverse.c \ src/io_thread.c src/io_thread.h \ src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \ src/tag.c src/tag_pool.c src/tag_handler.c \ @@ -1094,6 +1096,7 @@ test_read_tags_LDADD = \ $(TAG_LIBS) \ $(GLIB_LIBS) test_read_tags_SOURCES = test/read_tags.c \ + src/util/bit_reverse.c \ src/io_thread.c src/io_thread.h \ src/conf.c src/tokenizer.c src/utils.c src/string_util.c src/log.c \ src/tag.c src/tag_pool.c src/tag_handler.c \ diff --git a/src/decoder/dsdiff_decoder_plugin.c b/src/decoder/dsdiff_decoder_plugin.c index 751eff4d6..ae42002dd 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 #include /* 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; -- cgit v1.2.3