system/ByteOrder: new library for byte ordering / endianess

Replacing GLib macros.
This commit is contained in:
Max Kellermann
2013-10-16 21:09:19 +02:00
parent 08eca827b6
commit 5e26e2ab1d
16 changed files with 289 additions and 109 deletions

View File

@@ -18,15 +18,14 @@
*/
#include "PcmPack.hxx"
#include <glib.h>
#include "system/ByteOrder.hxx"
static void
pack_sample(uint8_t *dest, const int32_t *src0)
{
const uint8_t *src = (const uint8_t *)src0;
if (G_BYTE_ORDER == G_BIG_ENDIAN)
if (IsBigEndian())
++src;
*dest++ = *src++;
@@ -51,7 +50,7 @@ unpack_sample(int32_t *dest0, const uint8_t *src)
{
uint8_t *dest = (uint8_t *)dest0;
if (G_BYTE_ORDER == G_BIG_ENDIAN)
if (IsBigEndian())
/* extend the sign bit to the most fourth byte */
*dest++ = *src & 0x80 ? 0xff : 0x00;
@@ -59,7 +58,7 @@ unpack_sample(int32_t *dest0, const uint8_t *src)
*dest++ = *src++;
*dest++ = *src;
if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
if (IsLittleEndian())
/* extend the sign bit to the most fourth byte */
*dest++ = *src & 0x80 ? 0xff : 0x00;
}