17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _MULTIMEDIA_AUDIOTYPES_H
287c478bd9Sstevel@tonic-gate #define	_MULTIMEDIA_AUDIOTYPES_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef NO_EXTERN_C
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef __cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #endif /* NO_EXTERN_C */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <math.h>
397c478bd9Sstevel@tonic-gate #include <stdlib.h>
407c478bd9Sstevel@tonic-gate #include <float.h>
417c478bd9Sstevel@tonic-gate #include <limits.h>
427c478bd9Sstevel@tonic-gate #include <fcntl.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <audio_hdr.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate // Types used in the audio API
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate // Values used for indeterminate size (e.g., data passed through a pipe)
507c478bd9Sstevel@tonic-gate const double		AUDIO_UNKNOWN_TIME = DBL_MAX;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate // Error severity
537c478bd9Sstevel@tonic-gate enum AudioSeverity {
547c478bd9Sstevel@tonic-gate 	InitMessage,			// debugging message from constructor
557c478bd9Sstevel@tonic-gate 	InitFatal,			// fatal error from constructor
567c478bd9Sstevel@tonic-gate 	Message,			// debugging message
577c478bd9Sstevel@tonic-gate 	Warning,			// non-fatal error
587c478bd9Sstevel@tonic-gate 	Error,				// potentially severe error
597c478bd9Sstevel@tonic-gate 	Consistency,			// internal consistency warning
607c478bd9Sstevel@tonic-gate 	Fatal				// fatal internal error
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate // Used in SetPosition methods
647c478bd9Sstevel@tonic-gate enum Whence { Absolute = 0, Relative = 1, Relative_eof = 2};
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate // XXX - classes that ought to be defined elsewhere
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate // A Boolean 'primitive type' with values TRUE and FALSE
697c478bd9Sstevel@tonic-gate // undefine these in case they're defined elsewhere
707c478bd9Sstevel@tonic-gate #undef TRUE
717c478bd9Sstevel@tonic-gate #undef FALSE
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate // use bool_t 'cause boolean_t is already used under 5.0
747c478bd9Sstevel@tonic-gate // Since 4/93 can't use bool_t cause rpc/types.h typedefs it
757c478bd9Sstevel@tonic-gate // so use aud_bool_t
767c478bd9Sstevel@tonic-gate enum aud_bool_t {FALSE = 0, TRUE = 1};
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate class Boolean {
797c478bd9Sstevel@tonic-gate private:
807c478bd9Sstevel@tonic-gate 	aud_bool_t	value;		// value is TRUE or FALSE
817c478bd9Sstevel@tonic-gate public:
value(x)827c478bd9Sstevel@tonic-gate 	inline Boolean(aud_bool_t x = FALSE): value(x)	// Constructor
837c478bd9Sstevel@tonic-gate 	    { }
Boolean(int x)847c478bd9Sstevel@tonic-gate 	inline Boolean(int x)				// Constructor from int
857c478bd9Sstevel@tonic-gate 	    { value = (x == 0) ? FALSE : TRUE; }
867c478bd9Sstevel@tonic-gate 	inline Boolean operator=(int x)			// Assignment from int
877c478bd9Sstevel@tonic-gate 	    { return (value = (x == 0) ? FALSE : TRUE); }
887c478bd9Sstevel@tonic-gate 	inline operator int()				// Cast to integer
897c478bd9Sstevel@tonic-gate 	    { return ((value == TRUE) ? 1 : 0); }
907c478bd9Sstevel@tonic-gate 	inline Boolean operator!()			// Logical not
917c478bd9Sstevel@tonic-gate 	    { return ((value == TRUE) ? FALSE : TRUE); }
927c478bd9Sstevel@tonic-gate };
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate // A 'primitive type' for file access modes
957c478bd9Sstevel@tonic-gate enum fileaccess_t {
967c478bd9Sstevel@tonic-gate     NoAccess = 0, ReadOnly = 1, WriteOnly = 2, ReadWrite = 3,
977c478bd9Sstevel@tonic-gate     AppendOnly = 6, ReadAppend = 7
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate class FileAccess {
1017c478bd9Sstevel@tonic-gate private:
1027c478bd9Sstevel@tonic-gate 	fileaccess_t	mode;		// combined mode
1037c478bd9Sstevel@tonic-gate public:
mode(x)1047c478bd9Sstevel@tonic-gate 	FileAccess(fileaccess_t x = NoAccess): mode(x) { }	// Constructor
fileaccess_t()1057c478bd9Sstevel@tonic-gate 	inline operator fileaccess_t()			// Cast to enum
1067c478bd9Sstevel@tonic-gate 	    { return (mode); }
1077c478bd9Sstevel@tonic-gate 	inline operator int() {				// Cast to integer
1087c478bd9Sstevel@tonic-gate 	    switch (mode) {
1097c478bd9Sstevel@tonic-gate 	    case ReadOnly: return (O_RDONLY);
1107c478bd9Sstevel@tonic-gate 	    case WriteOnly: return (O_WRONLY);
1117c478bd9Sstevel@tonic-gate 	    case ReadWrite: return (O_RDWR);
1127c478bd9Sstevel@tonic-gate 	    case AppendOnly: return (O_WRONLY | O_APPEND);
1137c478bd9Sstevel@tonic-gate 	    case ReadAppend: return (O_RDWR | O_APPEND);
1141146e6b3SToomas Soome 	    case NoAccess:
1151146e6b3SToomas Soome 	    default:
1161146e6b3SToomas Soome 		return (-1);
1177c478bd9Sstevel@tonic-gate 	    }
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate 	// These tests depend on the actual enum values
Readable()1207c478bd9Sstevel@tonic-gate 	inline Boolean Readable() const			// TRUE if readable
1217c478bd9Sstevel@tonic-gate 	    { return ((int)mode & 1); }
Writeable()1227c478bd9Sstevel@tonic-gate 	inline Boolean Writeable() const		// TRUE if writeable
1237c478bd9Sstevel@tonic-gate 	    { return ((int)mode & 2); }
Append()1247c478bd9Sstevel@tonic-gate 	inline Boolean Append() const			// TRUE if append only
1257c478bd9Sstevel@tonic-gate 	    { return ((int)mode & 4); }
1267c478bd9Sstevel@tonic-gate };
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate // Define a small number corresponding to minor floating-point bit errors
1307c478bd9Sstevel@tonic-gate const double		AUDIO_MINFLOAT = .00000001;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate // Define a 'double' class that allows some leeway in magnitude checking
1337c478bd9Sstevel@tonic-gate // to try to correct for small errors due to floating-point imprecision
1347c478bd9Sstevel@tonic-gate class Double {
1357c478bd9Sstevel@tonic-gate private:
1367c478bd9Sstevel@tonic-gate 	double	val;
1377c478bd9Sstevel@tonic-gate public:
val(x)1387c478bd9Sstevel@tonic-gate 	Double(double x = 0.): val(x) { }
Double(const Double & x)1397c478bd9Sstevel@tonic-gate 	Double(const Double &x): val(x.val) { }
Undefined()1407c478bd9Sstevel@tonic-gate 	inline int Undefined() const
1417c478bd9Sstevel@tonic-gate 	    { return (val == AUDIO_UNKNOWN_TIME); }
1427c478bd9Sstevel@tonic-gate 	inline operator double() const
1437c478bd9Sstevel@tonic-gate 	    { return (val); }
1447c478bd9Sstevel@tonic-gate 	inline Double& operator += (double y)
1457c478bd9Sstevel@tonic-gate 	    { val += y; return (*this); }
1467c478bd9Sstevel@tonic-gate 	inline Double& operator -= (double y)
1477c478bd9Sstevel@tonic-gate 	    { val -= y; return (*this); }
148*164ffd89SToomas Soome 	Double& operator=(const Double&) = default;
1497c478bd9Sstevel@tonic-gate };
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate // inline double fabs(double x)
1527c478bd9Sstevel@tonic-gate //    { return ((x >= 0.) ? x : -x); }
1537c478bd9Sstevel@tonic-gate 
min(const Double & x,const Double & y)1547c478bd9Sstevel@tonic-gate inline double min(const Double& x, const Double& y) {
1557c478bd9Sstevel@tonic-gate 	return (((double)x <  (double)y) ? (double)x : (double)y);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate 
min(const Double & x,double y)1587c478bd9Sstevel@tonic-gate inline double min(const Double& x, double y) {
1597c478bd9Sstevel@tonic-gate 	return (((double)x <  (double)y) ? (double)x : (double)y);
1607c478bd9Sstevel@tonic-gate }
min(double x,const Double & y)1617c478bd9Sstevel@tonic-gate inline double min(double x, const Double& y) {
1627c478bd9Sstevel@tonic-gate 	return (((double)x <  (double)y) ? (double)x : (double)y);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate 
max(const Double & x,const Double & y)1657c478bd9Sstevel@tonic-gate inline double max(const Double& x, const Double& y) {
1667c478bd9Sstevel@tonic-gate 	return (((double)x >  (double)y) ? (double)x : (double)y);
1677c478bd9Sstevel@tonic-gate }
max(const Double & x,double y)1687c478bd9Sstevel@tonic-gate inline double max(const Double& x, double y) {
1697c478bd9Sstevel@tonic-gate 	return (((double)x >  (double)y) ? (double)x : (double)y);
1707c478bd9Sstevel@tonic-gate }
max(double x,const Double & y)1717c478bd9Sstevel@tonic-gate inline double max(double x, const Double& y) {
1727c478bd9Sstevel@tonic-gate 	return (((double)x >  (double)y) ? (double)x : (double)y);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate inline int operator == (const Double &x, const Double &y) {
1767c478bd9Sstevel@tonic-gate 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate inline int operator == (const Double &x, double y) {
1797c478bd9Sstevel@tonic-gate 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate inline int operator == (double x, const Double &y) {
1827c478bd9Sstevel@tonic-gate 	return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT);
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate inline int operator != (const Double &x, const Double &y) {
1867c478bd9Sstevel@tonic-gate 	return (!(x == y));
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate inline int operator != (const Double &x, double y) {
1897c478bd9Sstevel@tonic-gate 	return (!(x == y));
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate inline int operator != (double x, const Double &y) {
1927c478bd9Sstevel@tonic-gate 	return (!(x == y));
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate inline int operator <= (const Double &x, const Double &y) {
1967c478bd9Sstevel@tonic-gate 	return (((double)x < (double)y) || (x == y));
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate inline int operator <= (const Double &x, double y) {
1997c478bd9Sstevel@tonic-gate 	return (((double)x < (double)y) || (x == y));
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate inline int operator <= (double x, const Double &y)
2027c478bd9Sstevel@tonic-gate 	{ return (((double)x < (double)y) || (x == y)); }
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate inline int operator >= (const Double &x, const Double &y)
2057c478bd9Sstevel@tonic-gate 	{ return (((double)x > (double)y) || (x == y)); }
2067c478bd9Sstevel@tonic-gate inline int operator >= (const Double &x, double y) {
2077c478bd9Sstevel@tonic-gate 	return (((double)x > (double)y) || (x == y));
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate inline int operator >= (double x, const Double &y) {
2107c478bd9Sstevel@tonic-gate 	return (((double)x > (double)y) || (x == y));
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate inline int operator < (const Double &x, const Double &y) {
2147c478bd9Sstevel@tonic-gate 	return (!(x >= y));
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate inline int operator < (const Double &x, double y) {
2177c478bd9Sstevel@tonic-gate 	return (!(x >= y));
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate inline int operator < (double x, const Double &y) {
2207c478bd9Sstevel@tonic-gate 	return (!(x >= y));
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate inline int operator > (const Double &x, const Double &y) {
2247c478bd9Sstevel@tonic-gate 	return (!(x <= y));
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate inline int operator > (const Double &x, double y) {
2277c478bd9Sstevel@tonic-gate 	return (!(x <= y));
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate inline int operator > (double x, const Double &y) {
2307c478bd9Sstevel@tonic-gate 	return (!(x <= y));
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate inline Double& operator += (Double &x, const Double &y) {
2347c478bd9Sstevel@tonic-gate 	return (x += (double)y);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate inline double operator += (double &x, const Double &y) {
2377c478bd9Sstevel@tonic-gate 	return (x += (double)y);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate inline Double& operator -= (Double &x, const Double &y) {
2407c478bd9Sstevel@tonic-gate 	return (x -= (double)y);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate inline double operator -= (double &x, const Double &y) {
2437c478bd9Sstevel@tonic-gate 	return (x -= (double)y);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
Undefined(const Double & x)2467c478bd9Sstevel@tonic-gate inline int Undefined(const Double &x) {
2477c478bd9Sstevel@tonic-gate 	return (x.Undefined());
2487c478bd9Sstevel@tonic-gate }
Undefined(double x)2497c478bd9Sstevel@tonic-gate inline int Undefined(double x) {
2507c478bd9Sstevel@tonic-gate 	return (x == AUDIO_UNKNOWN_TIME);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate #ifdef NO_EXTERN_C
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate #endif
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate #endif /* NO_EXTERN_C */
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIOTYPES_H */
262