]> code.delx.au - pulseaudio/blob - src/polypcore/endianmacros.h
unhide padsp
[pulseaudio] / src / polypcore / endianmacros.h
1 #ifndef fooendianmacroshfoo
2 #define fooendianmacroshfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of polypaudio.
8
9 polypaudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 polypaudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with polypaudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <inttypes.h>
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #define INT16_SWAP(x) ( (int16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
32 #define UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
33 #define INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
34 #define UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
35
36 #define MAYBE_INT32_SWAP(c,x) ((c) ? INT32_SWAP(x) : x)
37 #define MAYBE_UINT32_SWAP(c,x) ((c) ? UINT32_SWAP(x) : x)
38
39 #ifdef WORDS_BIGENDIAN
40 #define INT16_FROM_LE(x) INT16_SWAP(x)
41 #define INT16_FROM_BE(x) ((int16_t)(x))
42
43 #define INT16_TO_LE(x) INT16_SWAP(x)
44 #define INT16_TO_BE(x) ((int16_t)(x))
45
46 #define UINT16_FROM_LE(x) UINT16_SWAP(x)
47 #define UINT16_FROM_BE(x) ((uint16_t)(x))
48
49 #define INT32_FROM_LE(x) INT32_SWAP(x)
50 #define INT32_FROM_BE(x) ((int32_t)(x))
51
52 #define UINT32_FROM_LE(x) UINT32_SWAP(x)
53 #define UINT32_FROM_BE(x) ((uint32_t)(x))
54
55 #define UINT32_TO_LE(x) UINT32_SWAP(x)
56 #define UINT32_TO_BE(x) ((uint32_t)(x))
57 #else
58 #define INT16_FROM_LE(x) ((int16_t)(x))
59 #define INT16_FROM_BE(x) INT16_SWAP(x)
60
61 #define INT16_TO_LE(x) ((int16_t)(x))
62 #define INT16_TO_BE(x) INT16_SWAP(x)
63
64 #define UINT16_FROM_LE(x) ((uint16_t)(x))
65 #define UINT16_FROM_BE(x) UINT16_SWAP(x)
66
67 #define INT32_FROM_LE(x) ((int32_t)(x))
68 #define INT32_FROM_BE(x) INT32_SWAP(x)
69
70 #define UINT32_FROM_LE(x) ((uint32_t)(x))
71 #define UINT32_FROM_BE(x) UINT32_SWAP(x)
72
73 #define UINT32_TO_LE(x) ((uint32_t)(x))
74 #define UINT32_TO_BE(x) UINT32_SWAP(x)
75 #endif
76
77 #endif