Commit e93dd374 authored by Max Kellermann's avatar Max Kellermann

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.
parent 0847ca4e
...@@ -28,11 +28,6 @@ ...@@ -28,11 +28,6 @@
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "pcm" #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 *pcm_byteswap_16(struct pcm_buffer *buffer,
const int16_t *src, size_t len) const int16_t *src, size_t len)
{ {
...@@ -42,19 +37,11 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer, ...@@ -42,19 +37,11 @@ const int16_t *pcm_byteswap_16(struct pcm_buffer *buffer,
assert(buf != NULL); assert(buf != NULL);
for (i = 0; i < len / 2; i++) for (i = 0; i < len / 2; i++)
buf[i] = swab16(src[i]); buf[i] = GUINT16_SWAP_LE_BE(src[i]);
return buf; 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 *pcm_byteswap_32(struct pcm_buffer *buffer,
const int32_t *src, size_t len) const int32_t *src, size_t len)
{ {
...@@ -64,7 +51,7 @@ const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer, ...@@ -64,7 +51,7 @@ const int32_t *pcm_byteswap_32(struct pcm_buffer *buffer,
assert(buf != NULL); assert(buf != NULL);
for (i = 0; i < len / 4; i++) for (i = 0; i < len / 4; i++)
buf[i] = swab32(src[i]); buf[i] = GUINT32_SWAP_LE_BE(src[i]);
return buf; return buf;
} }
......
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