aroarfw
byteorder.h
Go to the documentation of this file.
1 //byteorder.h:
2 
3 /*
4  * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013
5  *
6  * This file is part of aroarfw, a RoarAudio framework for
7  * embedded systems (µControlers).
8  *
9  * This file is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 3
11  * or (at your option) any later version as published by
12  * the Free Software Foundation.
13  *
14  * aroarfw is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this software; see the file COPYING. If not, write to
21  * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #ifndef _AROARFW_BYTEORDER_H_
26 #define _AROARFW_BYTEORDER_H_
27 
37 #define RBO_H2NB16(buf, v) ( \
38  ((uint16_t)(((unsigned char*)(buf))[0] = ((uint16_t)(v) >> 8) & 0xFF) << 8) + \
39  (uint16_t)(((unsigned char*)(buf))[1] = (uint16_t)(v) & 0xFF) \
40  )
41 
50 #define RBO_NB2H16(buf) ( \
51  ((uint16_t)(((unsigned char*)(buf))[0]) << 8) + \
52  (uint16_t)(((unsigned char*)(buf))[1]) \
53  )
54 
64 #define RBO_H2NB32(buf, v) ( \
65  ((uint32_t)(((unsigned char*)(buf))[0] = ((uint32_t)(v) >> 24) & 0xFF) << 24) + \
66  ((uint32_t)(((unsigned char*)(buf))[1] = ((uint32_t)(v) >> 16) & 0xFF) << 16) + \
67  ((uint32_t)(((unsigned char*)(buf))[2] = ((uint32_t)(v) >> 8) & 0xFF) << 8) + \
68  (uint32_t)(((unsigned char*)(buf))[3] = (uint32_t)(v) & 0xFF) \
69  )
70 
79 #define RBO_NB2H32(buf) ( \
80  ((uint32_t)(((unsigned char*)(buf))[0]) << 24) + \
81  ((uint32_t)(((unsigned char*)(buf))[1]) << 16) + \
82  ((uint32_t)(((unsigned char*)(buf))[2]) << 8) + \
83  (uint32_t)(((unsigned char*)(buf))[3]) \
84  )
85 
86 #endif
87 
88 //ll