]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/endianmacros.h
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / endianmacros.h
index 1b94de17d88a456f3147b3065fffe5c2d90f81e6..2b18cf8dd9da0777053afed1b856bfbdac2dc850 100644 (file)
@@ -9,7 +9,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #define PA_INT32_SWAP(x) ((int32_t) bswap_32((uint32_t) x))
 #define PA_UINT32_SWAP(x) ((uint32_t) bswap_32((uint32_t) x))
 #else
-#define PA_INT16_SWAP(x) ( (int16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
-#define PA_UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
-#define PA_INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
-#define PA_UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
+#define PA_INT16_SWAP(x) ( (int16_t) ( ((uint16_t) (x) >> 8) | ((uint16_t) (x) << 8) ) )
+#define PA_UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) (x) >> 8) | ((uint16_t) (x) << 8) ) )
+#define PA_INT32_SWAP(x) ( (int32_t) ( ((uint32_t) (x) >> 24) | ((uint32_t) (x) << 24) | (((uint32_t) (x) & 0xFF00) << 8) | ((((uint32_t) (x)) >> 8) & 0xFF00) ) )
+#define PA_UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) (x) >> 24) | ((uint32_t) (x) << 24) | (((uint32_t) (x) & 0xFF00) << 8) | ((((uint32_t) (x)) >> 8) & 0xFF00) ) )
 #endif
 
+static inline uint32_t PA_READ24BE(const uint8_t *p) {
+    return
+        ((uint32_t) p[0] << 16) |
+        ((uint32_t) p[1] << 8) |
+        ((uint32_t) p[2]);
+}
+
+static inline uint32_t PA_READ24LE(const uint8_t *p) {
+    return
+        ((uint32_t) p[2] << 16) |
+        ((uint32_t) p[1] << 8) |
+        ((uint32_t) p[0]);
+}
+
+static inline void PA_WRITE24BE(uint8_t *p, uint32_t u) {
+    p[0] = (uint8_t) (u >> 16);
+    p[1] = (uint8_t) (u >> 8);
+    p[2] = (uint8_t) u;
+}
+
+static inline void PA_WRITE24LE(uint8_t *p, uint32_t u) {
+    p[2] = (uint8_t) (u >> 16);
+    p[1] = (uint8_t) (u >> 8);
+    p[0] = (uint8_t) u;
+}
+
 static inline float PA_FLOAT32_SWAP(float x) {
     union {
         float f;
@@ -56,13 +82,13 @@ static inline float PA_FLOAT32_SWAP(float x) {
     return t.f;
 }
 
-#define PA_MAYBE_INT16_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : x)
-#define PA_MAYBE_UINT16_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : x)
+#define PA_MAYBE_INT16_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : (x))
+#define PA_MAYBE_UINT16_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : (x))
 
-#define PA_MAYBE_INT32_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : x)
-#define PA_MAYBE_UINT32_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : x)
+#define PA_MAYBE_INT32_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : (x))
+#define PA_MAYBE_UINT32_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : (x))
 
-#define PA_MAYBE_FLOAT32_SWAP(c,x) ((c) ? PA_FLOAT32_SWAP(x) : x)
+#define PA_MAYBE_FLOAT32_SWAP(c,x) ((c) ? PA_FLOAT32_SWAP(x) : (x))
 
 #ifdef WORDS_BIGENDIAN
  #define PA_INT16_FROM_LE(x) PA_INT16_SWAP(x)
@@ -91,6 +117,12 @@ static inline float PA_FLOAT32_SWAP(float x) {
 
  #define PA_FLOAT32_TO_LE(x) PA_FLOAT32_SWAP(x)
  #define PA_FLOAT32_TO_BE(x) ((float) (x))
+
+ #define PA_READ24NE(x) PA_READ24BE(x)
+ #define PA_WRITE24NE(x,y) PA_WRITE24BE((x),(y))
+
+ #define PA_READ24RE(x) PA_READ24LE(x)
+ #define PA_WRITE24RE(x,y) PA_WRITE24LE((x),(y))
 #else
  #define PA_INT16_FROM_LE(x) ((int16_t)(x))
  #define PA_INT16_FROM_BE(x) PA_INT16_SWAP(x)
@@ -118,6 +150,12 @@ static inline float PA_FLOAT32_SWAP(float x) {
 
  #define PA_FLOAT32_TO_LE(x) ((float) (x))
  #define PA_FLOAT32_TO_BE(x) PA_FLOAT32_SWAP(x)
+
+ #define PA_READ24NE(x) PA_READ24LE(x)
+ #define PA_WRITE24NE(x,y) PA_WRITE24LE((x),(y))
+
+ #define PA_READ24RE(x) PA_READ24BE(x)
+ #define PA_WRITE24RE(x,y) PA_WRITE24BE((x),(y))
 #endif
 
 #endif