xref: /onnv-gate/usr/src/cmd/audio/include/audio_hdr.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1992-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _MULTIMEDIA_AUDIO_HDR_H
28*0Sstevel@tonic-gate #define	_MULTIMEDIA_AUDIO_HDR_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef __cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * Define an in-core audio data header.
38*0Sstevel@tonic-gate  *
39*0Sstevel@tonic-gate  * This is different that the on-disk file header.
40*0Sstevel@tonic-gate  * The fields defined here are preliminary at best.
41*0Sstevel@tonic-gate  */
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate  * The audio header contains the following fields:
45*0Sstevel@tonic-gate  *
46*0Sstevel@tonic-gate  *      endian                  Byte order of 16-bit or greater PCM,
47*0Sstevel@tonic-gate  *                                and possibly floating point data.
48*0Sstevel@tonic-gate  *
49*0Sstevel@tonic-gate  *	sample_rate		Number of samples per second (per channel).
50*0Sstevel@tonic-gate  *
51*0Sstevel@tonic-gate  *	samples_per_unit	This field describes the number of samples
52*0Sstevel@tonic-gate  *				  represented by each sample unit (which, by
53*0Sstevel@tonic-gate  *				  definition, are aligned on byte boundaries).
54*0Sstevel@tonic-gate  *				  Audio samples may be stored individually
55*0Sstevel@tonic-gate  *				  or, in the case of compressed formats
56*0Sstevel@tonic-gate  *				  (e.g., ADPCM), grouped in algorithm-
57*0Sstevel@tonic-gate  *				  specific ways.  If the data is bit-packed,
58*0Sstevel@tonic-gate  *				  this field tells the number of samples
59*0Sstevel@tonic-gate  *				  needed to get to a byte boundary.
60*0Sstevel@tonic-gate  *
61*0Sstevel@tonic-gate  *	bytes_per_unit		Number of bytes stored for each sample unit
62*0Sstevel@tonic-gate  *
63*0Sstevel@tonic-gate  *	channels		Number of interleaved sample units.
64*0Sstevel@tonic-gate  *				   For any given time quantum, the set
65*0Sstevel@tonic-gate  *				   consisting of 'channels' sample units
66*0Sstevel@tonic-gate  *				   is called a sample frame.  Seeks in
67*0Sstevel@tonic-gate  *				   the data should be aligned to the start
68*0Sstevel@tonic-gate  *				   of the nearest sample frame.
69*0Sstevel@tonic-gate  *
70*0Sstevel@tonic-gate  *	encoding		Data encoding format.
71*0Sstevel@tonic-gate  *
72*0Sstevel@tonic-gate  *	data_size		Number of bytes in the data.
73*0Sstevel@tonic-gate  *				   This value is advisory only, and may
74*0Sstevel@tonic-gate  *				   be set to the value AUDIO_UNKNOWN_SIZE
75*0Sstevel@tonic-gate  *				   if the data size is unknown (for
76*0Sstevel@tonic-gate  *				   instance, if the data is being
77*0Sstevel@tonic-gate  *				   recorded or generated and piped
78*0Sstevel@tonic-gate  *				   to another process).
79*0Sstevel@tonic-gate  *
80*0Sstevel@tonic-gate  * The first four values are used to compute the byte offset given a
81*0Sstevel@tonic-gate  * particular time, and vice versa.  Specifically:
82*0Sstevel@tonic-gate  *
83*0Sstevel@tonic-gate  *	seconds = offset / C
84*0Sstevel@tonic-gate  *	offset = seconds * C
85*0Sstevel@tonic-gate  * where:
86*0Sstevel@tonic-gate  *	C = (channels * bytes_per_unit * sample_rate) / samples_per_unit
87*0Sstevel@tonic-gate  *
88*0Sstevel@tonic-gate  *
89*0Sstevel@tonic-gate  */
90*0Sstevel@tonic-gate typedef struct {
91*0Sstevel@tonic-gate 	unsigned	sample_rate;		/* samples per second */
92*0Sstevel@tonic-gate 	unsigned	samples_per_unit;	/* samples per unit */
93*0Sstevel@tonic-gate 	unsigned	bytes_per_unit;		/* bytes per sample unit */
94*0Sstevel@tonic-gate 	unsigned	channels;		/* # of interleaved channels */
95*0Sstevel@tonic-gate 	unsigned	encoding;		/* data encoding format */
96*0Sstevel@tonic-gate 	unsigned	endian;			/* byte order */
97*0Sstevel@tonic-gate 	unsigned	data_size;		/* length of data (optional) */
98*0Sstevel@tonic-gate } Audio_hdr;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate /*
101*0Sstevel@tonic-gate  * Define the possible encoding types.
102*0Sstevel@tonic-gate  * Note that the names that overlap the encodings in <sun/audioio.h>
103*0Sstevel@tonic-gate  * must have the same values.
104*0Sstevel@tonic-gate  */
105*0Sstevel@tonic-gate #define	AUDIO_ENCODING_NONE	(0)	/* No encoding specified ... */
106*0Sstevel@tonic-gate #define	AUDIO_ENCODING_ULAW	(1)	/* ISDN u-law */
107*0Sstevel@tonic-gate #define	AUDIO_ENCODING_ALAW	(2)	/* ISDN A-law */
108*0Sstevel@tonic-gate #define	AUDIO_ENCODING_LINEAR	(3)	/* PCM 2's-complement (0-center) */
109*0Sstevel@tonic-gate #define	AUDIO_ENCODING_FLOAT	(100)	/* IEEE float (-1. <-> +1.) */
110*0Sstevel@tonic-gate #define	AUDIO_ENCODING_G721	(101)	/* CCITT g.721 ADPCM */
111*0Sstevel@tonic-gate #define	AUDIO_ENCODING_G722	(102)	/* CCITT g.722 ADPCM */
112*0Sstevel@tonic-gate #define	AUDIO_ENCODING_G723	(103)	/* CCITT g.723 ADPCM */
113*0Sstevel@tonic-gate #define	AUDIO_ENCODING_DVI	(104)	/* DVI ADPCM */
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate /*
116*0Sstevel@tonic-gate  * Define the possible endian types.
117*0Sstevel@tonic-gate  */
118*0Sstevel@tonic-gate #define	AUDIO_ENDIAN_BIG 0	/* SPARC, 68000, etc. */
119*0Sstevel@tonic-gate #define	AUDIO_ENDIAN_SMALL 1	/* Intel */
120*0Sstevel@tonic-gate #define	AUDIO_ENDIAN_UNKNOWN 2	/* Unknown endian */
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate /* Value used for indeterminate size (e.g., data passed through a pipe) */
123*0Sstevel@tonic-gate #define	AUDIO_UNKNOWN_SIZE	((unsigned)(~0))
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate /* Define conversion macros for integer<->floating-point conversions */
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate /* double to 8,16,32-bit linear */
129*0Sstevel@tonic-gate #define	audio_d2c(X)		((X) >= 1. ? 127 : (X) <= -1. ? -127 :	\
130*0Sstevel@tonic-gate 				    (char)(rint((X) * 127.)))
131*0Sstevel@tonic-gate #define	audio_d2s(X)		((X) >= 1. ? 32767 : (X) <= -1. ? -32767 :\
132*0Sstevel@tonic-gate 				    (short)(rint((X) * 32767.)))
133*0Sstevel@tonic-gate #define	audio_d2l(X)		((X) >= 1. ? 2147483647 : (X) <= -1. ?	\
134*0Sstevel@tonic-gate 				    -2147483647 :			\
135*0Sstevel@tonic-gate 				    (long)(rint((X) * 2147483647.)))
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate /* 8,16,32-bit linear to double */
138*0Sstevel@tonic-gate #define	audio_c2d(X)		(((unsigned char)(X)) == 0x80 ? -1. :	\
139*0Sstevel@tonic-gate 				    ((double)((char)(X))) / 127.)
140*0Sstevel@tonic-gate #define	audio_s2d(X)		(((unsigned short)(X)) == 0x8000 ? -1. :\
141*0Sstevel@tonic-gate 				    ((double)((short)(X))) / 32767.)
142*0Sstevel@tonic-gate #define	audio_l2d(X)		(((unsigned long)(X)) == 0x80000000 ? -1. :\
143*0Sstevel@tonic-gate 				    ((double)((long)(X))) / 2147483647.)
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate #ifdef __cplusplus
146*0Sstevel@tonic-gate }
147*0Sstevel@tonic-gate #endif
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate #endif /* !_MULTIMEDIA_AUDIO_HDR_H */
150