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.
This commit is contained in:
@@ -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,
|
|||||||
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,
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user