aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--src/audio_format.h5
-rw-r--r--src/filter/convert_filter_plugin.c1
-rw-r--r--src/output_thread.c10
-rw-r--r--src/pcm_byteswap.c71
-rw-r--r--src/pcm_byteswap.h50
-rw-r--r--src/pcm_convert.c19
7 files changed, 154 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index 5c53ca5c1..5bfaae210 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -114,6 +114,7 @@ mpd_headers = \
src/pcm_convert.h \
src/pcm_volume.h \
src/pcm_mix.h \
+ src/pcm_byteswap.h \
src/pcm_channels.h \
src/pcm_format.h \
src/pcm_resample.h \
@@ -218,6 +219,7 @@ src_mpd_SOURCES = \
src/pcm_convert.c \
src/pcm_volume.c \
src/pcm_mix.c \
+ src/pcm_byteswap.c \
src/pcm_channels.c \
src/pcm_format.c \
src/pcm_resample.c \
@@ -708,7 +710,7 @@ test_run_filter_SOURCES = test/run_filter.c \
src/filter_plugin.c \
src/filter_registry.c \
src/conf.c src/buffer2array.c src/utils.c \
- src/pcm_volume.c src/pcm_convert.c \
+ src/pcm_volume.c src/pcm_convert.c src/pcm_byteswap.c \
src/pcm_format.c src/pcm_channels.c src/pcm_dither.c \
src/pcm_resample.c src/pcm_resample_fallback.c \
src/audio_parser.c \
diff --git a/src/audio_format.h b/src/audio_format.h
index e325c1b38..54514ff93 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -27,6 +27,7 @@ struct audio_format {
uint32_t sample_rate;
uint8_t bits;
uint8_t channels;
+ uint8_t reverse_endian;
};
static inline void audio_format_clear(struct audio_format *af)
@@ -34,6 +35,7 @@ static inline void audio_format_clear(struct audio_format *af)
af->sample_rate = 0;
af->bits = 0;
af->channels = 0;
+ af->reverse_endian = 0;
}
static inline void audio_format_init(struct audio_format *af,
@@ -97,7 +99,8 @@ static inline bool audio_format_equals(const struct audio_format *a,
{
return a->sample_rate == b->sample_rate &&
a->bits == b->bits &&
- a->channels == b->channels;
+ a->channels == b->channels &&
+ a->reverse_endian == b->reverse_endian;
}
/**
diff --git a/src/filter/convert_filter_plugin.c b/src/filter/convert_filter_plugin.c
index f4d03ebef..b7f16de4f 100644
--- a/src/filter/convert_filter_plugin.c
+++ b/src/filter/convert_filter_plugin.c
@@ -149,6 +149,7 @@ convert_filter_set(struct filter *_filter,
assert(audio_format_valid(&filter->out_audio_format));
assert(out_audio_format != NULL);
assert(audio_format_valid(out_audio_format));
+ assert(filter->in_audio_format.reverse_endian == 0);
filter->out_audio_format = *out_audio_format;
}
diff --git a/src/output_thread.c b/src/output_thread.c
index 2592b2456..c7bd069b1 100644
--- a/src/output_thread.c
+++ b/src/output_thread.c
@@ -93,18 +93,20 @@ ao_open(struct audio_output *ao)
g_mutex_unlock(ao->mutex);
g_debug("opened plugin=%s name=\"%s\" "
- "audio_format=%u:%u:%u",
+ "audio_format=%u:%u:%u:%u",
ao->plugin->name, ao->name,
ao->out_audio_format.sample_rate,
ao->out_audio_format.bits,
- ao->out_audio_format.channels);
+ ao->out_audio_format.channels,
+ ao->out_audio_format.reverse_endian);
if (!audio_format_equals(&ao->in_audio_format,
&ao->out_audio_format))
- g_debug("converting from %u:%u:%u",
+ g_debug("converting from %u:%u:%u:%u",
ao->in_audio_format.sample_rate,
ao->in_audio_format.bits,
- ao->in_audio_format.channels);
+ ao->in_audio_format.channels,
+ ao->in_audio_format.reverse_endian);
}
static void
diff --git a/src/pcm_byteswap.c b/src/pcm_byteswap.c
new file mode 100644
index 000000000..6bdec1f24
--- /dev/null
+++ b/src/pcm_byteswap.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "pcm_byteswap.h"
+#include "pcm_buffer.h"
+
+#include <glib.h>
+
+#include <assert.h>
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "pcm"
+
+static inline uint16_t swab16(uint16_t x)
+{
+ return (x << 8) | (x >> 8);
+}
+
+const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer,
+ const int16_t *src, size_t len)
+{
+ unsigned i;
+ int16_t *buf = pcm_buffer_get(buffer, len);
+
+ if (!buf)
+ return NULL;
+
+ for (i = 0; i < len / 2; i++)
+ buf[i] = swab16(src[i]);
+
+ return buf;
+}
+
+static inline uint32_t swab32(uint32_t x)
+{
+ return (x << 24) |
+ ((x & 0xff00) << 8) |
+ ((x & 0xff0000) >> 8) |
+ (x >> 24);
+}
+
+const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
+ const int32_t *src, size_t len)
+{
+ unsigned i;
+ int32_t *buf = pcm_buffer_get(buffer, len);
+
+ if (!buf)
+ return NULL;
+
+ for (i = 0; i < len / 4; i++)
+ buf[i] = swab32(src[i]);
+
+ return buf;
+}
diff --git a/src/pcm_byteswap.h b/src/pcm_byteswap.h
new file mode 100644
index 000000000..e1196d9b2
--- /dev/null
+++ b/src/pcm_byteswap.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_PCM_BYTESWAP_H
+#define MPD_PCM_BYTESWAP_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+struct pcm_buffer;
+
+/**
+ * Changes the endianness of 16 bit PCM data.
+ *
+ * @param buffer the destination pcm_buffer object
+ * @param src the source PCM buffer
+ * @param src_size the number of bytes in #src
+ * @return the destination buffer
+ */
+const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer,
+ const int16_t *src, size_t len);
+
+/**
+ * Changes the endianness of 32-bit (or 24-bit) PCM data.
+ *
+ * @param buffer the destination pcm_buffer object
+ * @param src the source PCM buffer
+ * @param src_size the number of bytes in #src
+ * @return the destination buffer
+ */
+const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
+ const int32_t *src, size_t len);
+
+#endif
diff --git a/src/pcm_convert.c b/src/pcm_convert.c
index ebb4adff5..2d72628b2 100644
--- a/src/pcm_convert.c
+++ b/src/pcm_convert.c
@@ -20,6 +20,7 @@
#include "pcm_convert.h"
#include "pcm_channels.h"
#include "pcm_format.h"
+#include "pcm_byteswap.h"
#include "audio_format.h"
#include <assert.h>
@@ -83,6 +84,12 @@ pcm_convert_16(struct pcm_convert_state *state,
dest_format->sample_rate,
&len);
+ if (dest_format->reverse_endian) {
+ buf = pcm_byteswap_16(&state->format_buffer, buf, len);
+ if (!buf)
+ g_error("pcm_byteswap_16() failed");
+ }
+
*dest_size_r = len;
return buf;
}
@@ -120,6 +127,12 @@ pcm_convert_24(struct pcm_convert_state *state,
dest_format->sample_rate,
&len);
+ if (dest_format->reverse_endian) {
+ buf = pcm_byteswap_32(&state->format_buffer, buf, len);
+ if (!buf)
+ g_error("pcm_byteswap_32() failed");
+ }
+
*dest_size_r = len;
return buf;
}
@@ -157,6 +170,12 @@ pcm_convert_32(struct pcm_convert_state *state,
dest_format->sample_rate,
&len);
+ if (dest_format->reverse_endian) {
+ buf = pcm_byteswap_32(&state->format_buffer, buf, len);
+ if (!buf)
+ g_error("pcm_byteswap_32() failed");
+ }
+
*dest_size_r = len;
return buf;
}