aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_byteswap.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-10-10 07:58:27 +0200
committerMax Kellermann <max@duempel.org>2011-10-10 10:24:05 +0200
commite93dd374a46270d6cd873b7e2db557b346b1aac7 (patch)
tree2fafe9bb35041475df39fe2b16e6d99dde908578 /src/pcm_byteswap.c
parent0847ca4ec2e137d0eaa235d653217e8a913187f8 (diff)
downloadmpd-e93dd374a46270d6cd873b7e2db557b346b1aac7.tar.gz
mpd-e93dd374a46270d6cd873b7e2db557b346b1aac7.tar.xz
mpd-e93dd374a46270d6cd873b7e2db557b346b1aac7.zip
pcm_byteswap: use GLib byte swapping macros
GLib's macros are implemented with inline assembly, and probably a lot faster than our naive bit shifting implementation.
Diffstat (limited to '')
-rw-r--r--src/pcm_byteswap.c17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/pcm_byteswap.c b/src/pcm_byteswap.c
index 63f116211..13ed85bfe 100644
--- a/src/pcm_byteswap.c
+++ b/src/pcm_byteswap.c
@@ -28,11 +28,6 @@
#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)
{
@@ -42,19 +37,11 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer,
assert(buf != NULL);
for (i = 0; i < len / 2; i++)
- buf[i] = swab16(src[i]);
+ buf[i] = GUINT16_SWAP_LE_BE(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)
{
@@ -64,7 +51,7 @@ const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
assert(buf != NULL);
for (i = 0; i < len / 4; i++)
- buf[i] = swab32(src[i]);
+ buf[i] = GUINT32_SWAP_LE_BE(src[i]);
return buf;
}