annotate src/liblo-0.26/lo/lo_endian.h.in @ 122:62723f530572

Remove Vamp SDK (at least from OSX directory). We're beginning to include it in the main build instead.
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 18 Mar 2016 14:04:03 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 /*
cannam@89 2 * Copyright (C) 2004 Steve Harris
cannam@89 3 *
cannam@89 4 * This program is free software; you can redistribute it and/or
cannam@89 5 * modify it under the terms of the GNU Lesser General Public License
cannam@89 6 * as published by the Free Software Foundation; either version 2.1
cannam@89 7 * of the License, or (at your option) any later version.
cannam@89 8 *
cannam@89 9 * This program is distributed in the hope that it will be useful,
cannam@89 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@89 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@89 12 * GNU Lesser General Public License for more details.
cannam@89 13 *
cannam@89 14 * $Id$
cannam@89 15 */
cannam@89 16
cannam@89 17 #ifndef LO_ENDIAN_H
cannam@89 18 #define LO_ENDIAN_H
cannam@89 19
cannam@89 20 #include <sys/types.h>
cannam@89 21 #include <stdint.h>
cannam@89 22
cannam@89 23 #ifdef WIN32
cannam@89 24 #include <winsock2.h>
cannam@89 25 #include <ws2tcpip.h>
cannam@89 26 #else
cannam@89 27 #include <netinet/in.h>
cannam@89 28 #endif
cannam@89 29
cannam@89 30 #ifdef __cplusplus
cannam@89 31 extern "C" {
cannam@89 32 #endif
cannam@89 33
cannam@89 34 #define lo_swap16(x) htons(x)
cannam@89 35
cannam@89 36 #define lo_swap32(x) htonl(x)
cannam@89 37
cannam@89 38 /* These macros come from the Linux kernel */
cannam@89 39
cannam@89 40 #ifndef lo_swap16
cannam@89 41 #define lo_swap16(x) \
cannam@89 42 ({ \
cannam@89 43 uint16_t __x = (x); \
cannam@89 44 ((uint16_t)( \
cannam@89 45 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
cannam@89 46 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
cannam@89 47 })
cannam@89 48 #warning USING UNOPTIMISED ENDIAN STUFF
cannam@89 49 #endif
cannam@89 50
cannam@89 51 #ifndef lo_swap32
cannam@89 52 #define lo_swap32(x) \
cannam@89 53 ({ \
cannam@89 54 uint32_t __x = (x); \
cannam@89 55 ((uint32_t)( \
cannam@89 56 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
cannam@89 57 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
cannam@89 58 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
cannam@89 59 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
cannam@89 60 })
cannam@89 61 #endif
cannam@89 62
cannam@89 63 #if 0
cannam@89 64 #ifndef lo_swap64
cannam@89 65 #define lo_swap64(x) \
cannam@89 66 ({ \
cannam@89 67 uint64_t __x = (x); \
cannam@89 68 ((uint64_t)( \
cannam@89 69 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
cannam@89 70 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
cannam@89 71 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
cannam@89 72 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
cannam@89 73 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
cannam@89 74 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
cannam@89 75 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
cannam@89 76 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
cannam@89 77 })
cannam@89 78 #endif
cannam@89 79 #else
cannam@89 80
cannam@89 81 typedef union {
cannam@89 82 uint64_t all;
cannam@89 83 struct {
cannam@89 84 uint32_t a;
cannam@89 85 uint32_t b;
cannam@89 86 } part;
cannam@89 87 } lo_split64;
cannam@89 88
cannam@89 89 static inline uint64_t lo_swap64(uint64_t x)
cannam@89 90 {
cannam@89 91 lo_split64 in, out;
cannam@89 92
cannam@89 93 in.all = x;
cannam@89 94 out.part.a = lo_swap32(in.part.b);
cannam@89 95 out.part.b = lo_swap32(in.part.a);
cannam@89 96
cannam@89 97 return out.all;
cannam@89 98 }
cannam@89 99 #endif
cannam@89 100
cannam@89 101 /* Host to OSC and OSC to Host conversion macros */
cannam@89 102
cannam@89 103 #if @LO_BIGENDIAN@
cannam@89 104 #define lo_htoo16(x) (x)
cannam@89 105 #define lo_htoo32(x) (x)
cannam@89 106 #define lo_htoo64(x) (x)
cannam@89 107 #define lo_otoh16(x) (x)
cannam@89 108 #define lo_otoh32(x) (x)
cannam@89 109 #define lo_otoh64(x) (x)
cannam@89 110 #else
cannam@89 111 #define lo_htoo16 lo_swap16
cannam@89 112 #define lo_htoo32 lo_swap32
cannam@89 113 #define lo_htoo64 lo_swap64
cannam@89 114 #define lo_otoh16 lo_swap16
cannam@89 115 #define lo_otoh32 lo_swap32
cannam@89 116 #define lo_otoh64 lo_swap64
cannam@89 117 #endif
cannam@89 118
cannam@89 119 #ifdef __cplusplus
cannam@89 120 }
cannam@89 121 #endif
cannam@89 122
cannam@89 123 #endif
cannam@89 124
cannam@89 125 /* vi:set ts=8 sts=4 sw=4: */