aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-10 09:30:49 +0200
committerMax Kellermann <max@duempel.org>2011-10-10 10:13:43 +0200
commitece6037a1e654ff01e4238df65490edf68a568a7 (patch)
treed28ee7bb3a25b30473a0fb6b4c613ec993d9acff /src
parentbea678a7cda2400d1326f77d58d2083b3dc2162f (diff)
downloadmpd-ece6037a1e654ff01e4238df65490edf68a568a7.tar.gz
mpd-ece6037a1e654ff01e4238df65490edf68a568a7.tar.xz
mpd-ece6037a1e654ff01e4238df65490edf68a568a7.zip
pcm_byteswap: add function with sample_format overload
Diffstat (limited to '')
-rw-r--r--src/pcm_byteswap.c26
-rw-r--r--src/pcm_byteswap.h17
2 files changed, 43 insertions, 0 deletions
diff --git a/src/pcm_byteswap.c b/src/pcm_byteswap.c
index 4e604c79a..63f116211 100644
--- a/src/pcm_byteswap.c
+++ b/src/pcm_byteswap.c
@@ -68,3 +68,29 @@ const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
return buf;
}
+
+const void *
+pcm_byteswap(struct pcm_buffer *buffer, enum sample_format format,
+ const void *src, size_t size)
+{
+ switch (format) {
+ case SAMPLE_FORMAT_UNDEFINED:
+ case SAMPLE_FORMAT_S24:
+ /* not implemented */
+ return NULL;
+
+ case SAMPLE_FORMAT_S8:
+ return src;
+
+ case SAMPLE_FORMAT_S16:
+ return pcm_byteswap_16(buffer, src, size);
+
+ case SAMPLE_FORMAT_S24_P32:
+ case SAMPLE_FORMAT_S32:
+ return pcm_byteswap_32(buffer, src, size);
+ }
+
+ /* unreachable */
+ assert(false);
+ return NULL;
+}
diff --git a/src/pcm_byteswap.h b/src/pcm_byteswap.h
index 1098a2fe1..0836a2512 100644
--- a/src/pcm_byteswap.h
+++ b/src/pcm_byteswap.h
@@ -20,6 +20,8 @@
#ifndef MPD_PCM_BYTESWAP_H
#define MPD_PCM_BYTESWAP_H
+#include "audio_format.h"
+
#include <stdint.h>
#include <stddef.h>
@@ -47,4 +49,19 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer,
const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
const int32_t *src, size_t len);
+/**
+ * Changes the endianness of PCM data.
+ *
+ * @param buffer the destination pcm_buffer object
+ * @param format the sample format (both input and output)
+ * @param src the source PCM buffer
+ * @param src_size the number of bytes in #src
+ * @return the destination buffer, or NULL if the sample format is not
+ * supported
+ */
+G_GNUC_MALLOC
+const void *
+pcm_byteswap(struct pcm_buffer *buffer, enum sample_format format,
+ const void *src, size_t size);
+
#endif