diff options
author | Max Kellermann <max@duempel.org> | 2012-03-21 19:07:15 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-03-21 19:10:57 +0100 |
commit | 7ebf8e66c9336f93ddf9d747a917f59595fd9dec (patch) | |
tree | 2ed9ee77d696d67100f2310203fc9580306d3473 /src/decoder/pcm_decoder_plugin.c | |
parent | 62218fe59d14cca29e15e8c687a568c850cb6003 (diff) | |
download | mpd-7ebf8e66c9336f93ddf9d747a917f59595fd9dec.tar.gz mpd-7ebf8e66c9336f93ddf9d747a917f59595fd9dec.tar.xz mpd-7ebf8e66c9336f93ddf9d747a917f59595fd9dec.zip |
decoder/pcm: always supply host byte order samples
Don't use audio_format.reverse_endian.
Diffstat (limited to 'src/decoder/pcm_decoder_plugin.c')
-rw-r--r-- | src/decoder/pcm_decoder_plugin.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/decoder/pcm_decoder_plugin.c b/src/decoder/pcm_decoder_plugin.c index 545f7fc82..fc7dffc05 100644 --- a/src/decoder/pcm_decoder_plugin.c +++ b/src/decoder/pcm_decoder_plugin.c @@ -20,6 +20,7 @@ #include "config.h" #include "decoder/pcm_decoder_plugin.h" #include "decoder_api.h" +#include "util/byte_reverse.h" #include <glib.h> #include <unistd.h> @@ -31,35 +32,25 @@ static void pcm_stream_decode(struct decoder *decoder, struct input_stream *is) { - static const struct audio_format host_audio_format = { + static const struct audio_format audio_format = { .sample_rate = 44100, .format = SAMPLE_FORMAT_S16, .channels = 2, }; - static const struct audio_format reverse_audio_format = { - .sample_rate = 44100, - .format = SAMPLE_FORMAT_S16, - .channels = 2, - .reverse_endian = true, - }; - - const struct audio_format *audio_format = - (is->mime == NULL || - strcmp(is->mime, "audio/x-mpd-cdda-pcm-reverse") != 0) - ? &host_audio_format - : &reverse_audio_format; + const bool reverse_endian = is->mime != NULL && + strcmp(is->mime, "audio/x-mpd-cdda-pcm-reverse") == 0; GError *error = NULL; enum decoder_command cmd; - double time_to_size = audio_format_time_to_size(audio_format); + double time_to_size = audio_format_time_to_size(&audio_format); float total_time = -1; if (is->size >= 0) total_time = is->size / time_to_size; - decoder_initialized(decoder, audio_format, is->seekable, total_time); + decoder_initialized(decoder, &audio_format, is->seekable, total_time); do { char buffer[4096]; @@ -70,6 +61,12 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) if (nbytes == 0 && input_stream_lock_eof(is)) break; + if (reverse_endian) + /* make sure we deliver samples in host byte order */ + reverse_bytes_16((uint16_t *)buffer, + (uint16_t *)buffer, + (uint16_t *)(buffer + nbytes)); + cmd = nbytes > 0 ? decoder_data(decoder, is, buffer, nbytes, 0) |