1 /*
2      File: CAByteOrder.h
3  Abstract: Part of CoreAudio Utility Classes
4   Version: 1.1
5 
6  Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
7  Inc. ("Apple") in consideration of your agreement to the following
8  terms, and your use, installation, modification or redistribution of
9  this Apple software constitutes acceptance of these terms.  If you do
10  not agree with these terms, please do not use, install, modify or
11  redistribute this Apple software.
12 
13  In consideration of your agreement to abide by the following terms, and
14  subject to these terms, Apple grants you a personal, non-exclusive
15  license, under Apple's copyrights in this original Apple software (the
16  "Apple Software"), to use, reproduce, modify and redistribute the Apple
17  Software, with or without modifications, in source and/or binary forms;
18  provided that if you redistribute the Apple Software in its entirety and
19  without modifications, you must retain this notice and the following
20  text and disclaimers in all such redistributions of the Apple Software.
21  Neither the name, trademarks, service marks or logos of Apple Inc. may
22  be used to endorse or promote products derived from the Apple Software
23  without specific prior written permission from Apple.  Except as
24  expressly stated in this notice, no other rights or licenses, express or
25  implied, are granted by Apple herein, including but not limited to any
26  patent rights that may be infringed by your derivative works or by other
27  works in which the Apple Software may be incorporated.
28 
29  The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
30  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34 
35  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42  POSSIBILITY OF SUCH DAMAGE.
43 
44  Copyright (C) 2014 Apple Inc. All Rights Reserved.
45 
46 */
47 #if !defined(__CAByteOrder_h__)
48 #define __CAByteOrder_h__
49 
50 //=============================================================================
51 //	Includes
52 //=============================================================================
53 
54 //	System Includes
55 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
56 	#include <CoreFoundation/CoreFoundation.h>
57 #else
58 	#include "CoreFoundation.h"
59 #endif
60 
61 
62 #if defined(__cplusplus)
63 extern "C" {
64 #endif
65 
CASwapFloat32(Float32 arg)66 CF_INLINE Float32 CASwapFloat32 (Float32 arg) {
67 	union {
68 		Float32 f;
69 		UInt32 i;
70 	} flip;
71 
72 	flip.f = arg;
73 	flip.i = CFSwapInt32 (flip.i);
74 
75 	return flip.f;
76 }
77 
CASwapFloat64(Float64 arg)78 CF_INLINE Float64 CASwapFloat64 (Float64 arg) {
79 	union {
80 		Float64 f;
81 		UInt64 i;
82 	} flip;
83 
84 	flip.f = arg;
85 	flip.i = CFSwapInt64 (flip.i);
86 
87 	return flip.f;
88 }
89 
90 #pragma mark -Flippers
91 
CASwapFloat32BigToHost(Float32 arg)92 CF_INLINE Float32 CASwapFloat32BigToHost(Float32 arg) {
93 #if defined(__BIG_ENDIAN__)
94     return arg;
95 #else
96 	return CASwapFloat32(arg);
97 #endif
98 }
99 
CASwapFloat64BigToHost(Float64 arg)100 CF_INLINE Float64 CASwapFloat64BigToHost(Float64 arg) {
101 #if defined(__BIG_ENDIAN__)
102     return arg;
103 #else
104 	return CASwapFloat64(arg);
105 #endif
106 }
107 
CASwapFloat32HostToBig(Float32 arg)108 CF_INLINE Float32 CASwapFloat32HostToBig(Float32 arg) {
109 #if defined(__BIG_ENDIAN__)
110     return arg;
111 #else
112 	return CASwapFloat32(arg);
113 #endif
114 }
115 
CASwapFloat64HostToBig(Float64 arg)116 CF_INLINE Float64 CASwapFloat64HostToBig(Float64 arg) {
117 #if defined(__BIG_ENDIAN__)
118     return arg;
119 #else
120 	return CASwapFloat64(arg);
121 #endif
122 }
123 
CASwapFloat32LittleToHost(Float32 arg)124 CF_INLINE Float32 CASwapFloat32LittleToHost(Float32 arg) {
125 #if defined(__LITTLE_ENDIAN__)
126     return arg;
127 #else
128 	return CASwapFloat32(arg);
129 #endif
130 }
131 
CASwapFloat64LittleToHost(Float64 arg)132 CF_INLINE Float64 CASwapFloat64LittleToHost(Float64 arg) {
133 #if defined(__LITTLE_ENDIAN__)
134     return arg;
135 #else
136 	return CASwapFloat64(arg);
137 #endif
138 }
139 
CASwapFloat32HostToLittle(Float32 arg)140 CF_INLINE Float32 CASwapFloat32HostToLittle(Float32 arg) {
141 #if defined(__LITTLE_ENDIAN__)
142     return arg;
143 #else
144 	return CASwapFloat32(arg);
145 #endif
146 }
147 
CASwapFloat64HostToLittle(Float64 arg)148 CF_INLINE Float64 CASwapFloat64HostToLittle(Float64 arg) {
149 #if defined(__LITTLE_ENDIAN__)
150     return arg;
151 #else
152 	return CASwapFloat64(arg);
153 #endif
154 }
155 
156 
157 #if defined(__cplusplus)
158 }
159 #endif
160 
161 #endif
162