annotate win32-mingw/include/lo/lo_endian.h @ 23:619f715526df sv_v2.1

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