Commit 238c3ada authored by Max Kellermann's avatar Max Kellermann

decoder/dsdiff: reverse bits to most significant bit first

Allow to remove this complexity from the MPD core.
parent c1d0a8b5
...@@ -1046,6 +1046,7 @@ test_dump_playlist_LDADD = \ ...@@ -1046,6 +1046,7 @@ test_dump_playlist_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_dump_playlist_SOURCES = test/dump_playlist.c \ test_dump_playlist_SOURCES = test/dump_playlist.c \
$(DECODER_SRC) \ $(DECODER_SRC) \
src/util/bit_reverse.c \
src/io_thread.c src/io_thread.h \ src/io_thread.c src/io_thread.h \
src/conf.c src/tokenizer.c src/utils.c src/string_util.c\ src/conf.c src/tokenizer.c src/utils.c src/string_util.c\
src/uri.c \ src/uri.c \
...@@ -1072,6 +1073,7 @@ test_run_decoder_LDADD = \ ...@@ -1072,6 +1073,7 @@ test_run_decoder_LDADD = \
$(GLIB_LIBS) $(GLIB_LIBS)
test_run_decoder_SOURCES = test/run_decoder.c \ test_run_decoder_SOURCES = test/run_decoder.c \
test/stdbin.h \ test/stdbin.h \
src/util/bit_reverse.c \
src/io_thread.c src/io_thread.h \ 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/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 \ src/tag.c src/tag_pool.c src/tag_handler.c \
...@@ -1094,6 +1096,7 @@ test_read_tags_LDADD = \ ...@@ -1094,6 +1096,7 @@ test_read_tags_LDADD = \
$(TAG_LIBS) \ $(TAG_LIBS) \
$(GLIB_LIBS) $(GLIB_LIBS)
test_read_tags_SOURCES = test/read_tags.c \ test_read_tags_SOURCES = test/read_tags.c \
src/util/bit_reverse.c \
src/io_thread.c src/io_thread.h \ 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/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 \ src/tag.c src/tag_pool.c src/tag_handler.c \
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "dsdiff_decoder_plugin.h" #include "dsdiff_decoder_plugin.h"
#include "decoder_api.h" #include "decoder_api.h"
#include "audio_check.h" #include "audio_check.h"
#include "util/bit_reverse.h"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */ #include <stdio.h> /* for SEEK_SET, SEEK_CUR */
...@@ -54,14 +55,12 @@ struct dsdiff_metadata { ...@@ -54,14 +55,12 @@ struct dsdiff_metadata {
unsigned sample_rate, channels; unsigned sample_rate, channels;
}; };
static enum sample_format dsd_sample_format; static bool lsbitfirst;
static bool static bool
dsdiff_init(const struct config_param *param) dsdiff_init(const struct config_param *param)
{ {
dsd_sample_format = config_get_block_bool(param, "lsbitfirst", false) lsbitfirst = config_get_block_bool(param, "lsbitfirst", false);
? SAMPLE_FORMAT_DSD_LSBFIRST
: SAMPLE_FORMAT_DSD;
return true; return true;
} }
...@@ -301,6 +300,13 @@ dsdiff_read_metadata(struct decoder *decoder, struct input_stream *is, ...@@ -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. * Decode one "DSD" chunk.
*/ */
...@@ -332,6 +338,9 @@ dsdiff_decode_chunk(struct decoder *decoder, struct input_stream *is, ...@@ -332,6 +338,9 @@ dsdiff_decode_chunk(struct decoder *decoder, struct input_stream *is,
chunk_size -= nbytes; chunk_size -= nbytes;
if (lsbitfirst)
bit_reverse_buffer(buffer, buffer + nbytes);
enum decoder_command cmd = enum decoder_command cmd =
decoder_data(decoder, is, buffer, nbytes, 0); decoder_data(decoder, is, buffer, nbytes, 0);
switch (cmd) { switch (cmd) {
...@@ -367,7 +376,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is) ...@@ -367,7 +376,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
GError *error = NULL; GError *error = NULL;
struct audio_format audio_format; struct audio_format audio_format;
if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8, if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
dsd_sample_format, SAMPLE_FORMAT_DSD,
metadata.channels, &error)) { metadata.channels, &error)) {
g_warning("%s", error->message); g_warning("%s", error->message);
g_error_free(error); g_error_free(error);
...@@ -420,7 +429,7 @@ dsdiff_scan_stream(struct input_stream *is, ...@@ -420,7 +429,7 @@ dsdiff_scan_stream(struct input_stream *is,
struct audio_format audio_format; struct audio_format audio_format;
if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8, if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
dsd_sample_format, SAMPLE_FORMAT_DSD,
metadata.channels, NULL)) metadata.channels, NULL))
/* refuse to parse files which we cannot play anyway */ /* refuse to parse files which we cannot play anyway */
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment