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