xref: /titanic_52/usr/src/cmd/audio/include/AudioTypes.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIOTYPES_H
28 #define	_MULTIMEDIA_AUDIOTYPES_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef NO_EXTERN_C
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #endif /* NO_EXTERN_C */
39 
40 #include <math.h>
41 #include <stdlib.h>
42 #include <float.h>
43 #include <limits.h>
44 #include <fcntl.h>
45 #include <sys/types.h>
46 
47 #include <audio_hdr.h>
48 
49 // Types used in the audio API
50 
51 // Values used for indeterminate size (e.g., data passed through a pipe)
52 const double		AUDIO_UNKNOWN_TIME = DBL_MAX;
53 
54 // Error severity
55 enum AudioSeverity {
56 	InitMessage,			// debugging message from constructor
57 	InitFatal,			// fatal error from constructor
58 	Message,			// debugging message
59 	Warning,			// non-fatal error
60 	Error,				// potentially severe error
61 	Consistency,			// internal consistency warning
62 	Fatal				// fatal internal error
63 };
64 
65 // Used in SetPosition methods
66 enum Whence { Absolute = 0, Relative = 1, Relative_eof = 2};
67 
68 // XXX - classes that ought to be defined elsewhere
69 
70 // A Boolean 'primitive type' with values TRUE and FALSE
71 // undefine these in case they're defined elsewhere
72 #undef TRUE
73 #undef FALSE
74 
75 // use bool_t 'cause boolean_t is already used under 5.0
76 // Since 4/93 can't use bool_t cause rpc/types.h typedefs it
77 // so use aud_bool_t
78 enum aud_bool_t {FALSE = 0, TRUE = 1};
79 
80 class Boolean {
81 private:
82 	aud_bool_t	value;		// value is TRUE or FALSE
83 public:
84 	inline Boolean(aud_bool_t x = FALSE): value(x)	// Constructor
85 	    { }
86 	inline Boolean(int x)				// Constructor from int
87 	    { value = (x == 0) ? FALSE : TRUE; }
88 	inline Boolean operator=(int x)			// Assignment from int
89 	    { return (value = (x == 0) ? FALSE : TRUE); }
90 	inline operator int()				// Cast to integer
91 	    { return ((value == TRUE) ? 1 : 0); }
92 	inline Boolean operator!()			// Logical not
93 	    { return ((value == TRUE) ? FALSE : TRUE); }
94 };
95 
96 // A 'primitive type' for file access modes
97 enum fileaccess_t {
98     NoAccess = 0, ReadOnly = 1, WriteOnly = 2, ReadWrite = 3,
99     AppendOnly = 6, ReadAppend = 7
100 };
101 
102 class FileAccess {
103 private:
104 	fileaccess_t	mode;		// combined mode
105 public:
106 	FileAccess(fileaccess_t x = NoAccess): mode(x) { }	// Constructor
107 	inline operator fileaccess_t()			// Cast to enum
108 	    { return (mode); }
109 	inline operator int() {				// Cast to integer
110 	    switch (mode) {
111 	    case NoAccess: return (-1);
112 	    case ReadOnly: return (O_RDONLY);
113 	    case WriteOnly: return (O_WRONLY);
114 	    case ReadWrite: return (O_RDWR);
115 	    case AppendOnly: return (O_WRONLY | O_APPEND);
116 	    case ReadAppend: return (O_RDWR | O_APPEND);
117 	    }
118 	}
119 	// These tests depend on the actual enum values
120 	inline Boolean Readable() const			// TRUE if readable
121 	    { return ((int)mode & 1); }
122 	inline Boolean Writeable() const		// TRUE if writeable
123 	    { return ((int)mode & 2); }
124 	inline Boolean Append() const			// TRUE if append only
125 	    { return ((int)mode & 4); }
126 };
127 
128 
129 // Define a small number corresponding to minor floating-point bit errors
130 const double		AUDIO_MINFLOAT = .00000001;
131 
132 // Define a 'double' class that allows some leeway in magnitude checking
133 // to try to correct for small errors due to floating-point imprecision
134 class Double {
135 private:
136 	double	val;
137 public:
138 	Double(double x = 0.): val(x) { }
139 	Double(const Double &x): val(x.val) { }
140 	inline int Undefined() const
141 	    { return (val == AUDIO_UNKNOWN_TIME); }
142 	inline operator double() const
143 	    { return (val); }
144 	inline Double& operator += (double y)
145 	    { val += y; return (*this); }
146 	inline Double& operator -= (double y)
147 	    { val -= y; return (*this); }
148 };
149 
150 // inline double fabs(double x)
151 //    { return ((x >= 0.) ? x : -x); }
152 
153 inline double min(const Double& x, const Double& y) {
154 	return (((double)x <  (double)y) ? (double)x : (double)y);
155 }
156 
157 inline double min(const Double& x, double y) {
158 	return (((double)x <  (double)y) ? (double)x : (double)y);
159 }
160 inline double min(double x, const Double& y) {
161 	return (((double)x <  (double)y) ? (double)x : (double)y);
162 }
163 
164 inline double max(const Double& x, const Double& y) {
165 	return (((double)x >  (double)y) ? (double)x : (double)y);
166 }
167 inline double max(const Double& x, double y) {
168 	return (((double)x >  (double)y) ? (double)x : (double)y);
169 }
170 inline double max(double x, const Double& y) {
171 	return (((double)x >  (double)y) ? (double)x : (double)y);
172 }
173 
174 inline int operator == (const Double &x, const Double &y) {
175 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
176 }
177 inline int operator == (const Double &x, double y) {
178 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
179 }
180 inline int operator == (double x, const Double &y) {
181 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
182 }
183 
184 inline int operator != (const Double &x, const Double &y) {
185 	return (!(x == y));
186 }
187 inline int operator != (const Double &x, double y) {
188 	return (!(x == y));
189 }
190 inline int operator != (double x, const Double &y) {
191 	return (!(x == y));
192 }
193 
194 inline int operator <= (const Double &x, const Double &y) {
195 	return (((double)x < (double)y) || (x == y));
196 }
197 inline int operator <= (const Double &x, double y) {
198 	return (((double)x < (double)y) || (x == y));
199 }
200 inline int operator <= (double x, const Double &y)
201 	{ return (((double)x < (double)y) || (x == y)); }
202 
203 inline int operator >= (const Double &x, const Double &y)
204 	{ return (((double)x > (double)y) || (x == y)); }
205 inline int operator >= (const Double &x, double y) {
206 	return (((double)x > (double)y) || (x == y));
207 }
208 inline int operator >= (double x, const Double &y) {
209 	return (((double)x > (double)y) || (x == y));
210 }
211 
212 inline int operator < (const Double &x, const Double &y) {
213 	return (!(x >= y));
214 }
215 inline int operator < (const Double &x, double y) {
216 	return (!(x >= y));
217 }
218 inline int operator < (double x, const Double &y) {
219 	return (!(x >= y));
220 }
221 
222 inline int operator > (const Double &x, const Double &y) {
223 	return (!(x <= y));
224 }
225 inline int operator > (const Double &x, double y) {
226 	return (!(x <= y));
227 }
228 inline int operator > (double x, const Double &y) {
229 	return (!(x <= y));
230 }
231 
232 inline Double& operator += (Double &x, const Double &y) {
233 	return (x += (double)y);
234 }
235 inline double operator += (double &x, const Double &y) {
236 	return (x += (double)y);
237 }
238 inline Double& operator -= (Double &x, const Double &y) {
239 	return (x -= (double)y);
240 }
241 inline double operator -= (double &x, const Double &y) {
242 	return (x -= (double)y);
243 }
244 
245 inline int Undefined(const Double &x) {
246 	return (x.Undefined());
247 }
248 inline int Undefined(double x) {
249 	return (x == AUDIO_UNKNOWN_TIME);
250 }
251 
252 #ifdef NO_EXTERN_C
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* NO_EXTERN_C */
259 
260 #endif /* !_MULTIMEDIA_AUDIOTYPES_H */
261