xref: /titanic_51/usr/src/head/audio/au.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _AUDIO_AU_H
28*7c478bd9Sstevel@tonic-gate #define	_AUDIO_AU_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
36*7c478bd9Sstevel@tonic-gate extern "C" {
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /*
40*7c478bd9Sstevel@tonic-gate  * Define an on-disk audio file header for the AU file format.
41*7c478bd9Sstevel@tonic-gate  *
42*7c478bd9Sstevel@tonic-gate  * Note that there is an optional 'info' field that immediately follows this
43*7c478bd9Sstevel@tonic-gate  * structure in the file. It is an optional length field that is sometimes
44*7c478bd9Sstevel@tonic-gate  * used to store additional information. At the minimum, it is at
45*7c478bd9Sstevel@tonic-gate  * least 4 bytes.
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  * The offset field is problematic in the general case because the
48*7c478bd9Sstevel@tonic-gate  * field is really "data location", which does not ensure that all
49*7c478bd9Sstevel@tonic-gate  * the bytes between the header and the data are really 'info'.
50*7c478bd9Sstevel@tonic-gate  * Further, there are no absolute guarantees that the info is ASCII text.
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * When audio files are passed through pipes, the au_data_size field may
53*7c478bd9Sstevel@tonic-gate  * not be known in advance.  In such cases, au_data_size should be
54*7c478bd9Sstevel@tonic-gate  * set to AUDIO_AU_UNKNOWN_SIZE.
55*7c478bd9Sstevel@tonic-gate  */
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate struct au_filehdr {
58*7c478bd9Sstevel@tonic-gate 	uint32_t	au_magic;	/* magic number */
59*7c478bd9Sstevel@tonic-gate 	uint32_t	au_offset;	/* size of this header */
60*7c478bd9Sstevel@tonic-gate 	uint32_t	au_data_size;	/* length of data */
61*7c478bd9Sstevel@tonic-gate 	uint32_t	au_encoding;	/* data encoding format */
62*7c478bd9Sstevel@tonic-gate 	uint32_t	au_sample_rate;	/* samples per second */
63*7c478bd9Sstevel@tonic-gate 	uint32_t	au_channels;	/* number of interleaved channels */
64*7c478bd9Sstevel@tonic-gate };
65*7c478bd9Sstevel@tonic-gate typedef struct au_filehdr au_filehdr_t;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	/*
68*7c478bd9Sstevel@tonic-gate 	 *	This is the appearance of a typical AU audio file as described
69*7c478bd9Sstevel@tonic-gate 	 *	by this structure.
70*7c478bd9Sstevel@tonic-gate 	 *
71*7c478bd9Sstevel@tonic-gate 	 *	------------------------------------------------------------
72*7c478bd9Sstevel@tonic-gate 	 *	|			|		|		   |
73*7c478bd9Sstevel@tonic-gate 	 *	|   AU Audio Header	|    Info 	|   Audio Data	   |
74*7c478bd9Sstevel@tonic-gate 	 *	|			| (optional)	|		   |
75*7c478bd9Sstevel@tonic-gate 	 *	|			|		|		   |
76*7c478bd9Sstevel@tonic-gate 	 *	|	24 bytes	| 4 bytes (min)	|    n bytes	   |
77*7c478bd9Sstevel@tonic-gate 	 *	|			|		|		   |
78*7c478bd9Sstevel@tonic-gate 	 *	------------------------------------------------------------
79*7c478bd9Sstevel@tonic-gate 	 */
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate /* Define the magic number */
82*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_FILE_MAGIC	((uint32_t)0x2e736e64)	/* ".snd" */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate /* Unknown header size */
85*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_UNKNOWN_SIZE	((unsigned)(~0))	/* (unsigned) -1 */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /* Define the AU encoding fields */
88*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ULAW		(1)	/* 8-bit u-law */
89*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_LINEAR_8	(2)	/* 8-bit linear PCM */
90*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_LINEAR_16	(3)	/* 16-bit linear PCM */
91*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_LINEAR_24	(4)	/* 24-bit linear PCM */
92*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_LINEAR_32	(5)	/* 32-bit linear PCM */
93*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FLOAT		(6)	/* 32-bit IEEE floating point */
94*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_DOUBLE	(7)	/* 64-bit IEEE double */
95*7c478bd9Sstevel@tonic-gate 						/*   precision float */
96*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FRAGMENTED	(8)	/* Fragmented sample data */
97*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_DSP		(10)	/* DSP program */
98*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FIXED_8	(11)	/* 8-bit fixed point */
99*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FIXED_16	(12)	/* 16-bit fixed point */
100*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FIXED_24	(13)	/* 24-bit fixed point */
101*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_FIXED_32	(14)	/* 32-bit fixed point */
102*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_EMPHASIS	(18)	/* 16-bit linear with */
103*7c478bd9Sstevel@tonic-gate 						/*   emphasis */
104*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_COMPRESSED	(19)	/* 16-bit linear compressed */
105*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_EMP_COMP	(20)	/* 16-bit linear with */
106*7c478bd9Sstevel@tonic-gate 						/*   emphasis and compression */
107*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_MUSIC_KIT	(21)	/* Music kit DSP commands */
108*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ADPCM_G721	(23)	/* 4-bit CCITT G.721 ADPCM */
109*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ADPCM_G722	(24)	/* CCITT G.722 ADPCM */
110*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ADPCM_G723_3	(25)	/* CCITT G.723.3 ADPCM */
111*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ADPCM_G723_5	(26)	/* CCITT G.723.5 ADPCM */
112*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_ENCODING_ALAW		(27)	/* 8-bit A-law G.711 */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /* Byte swapping routines */
116*7c478bd9Sstevel@tonic-gate #if defined(_BIG_ENDIAN)
117*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_FILE2HOST(from, to)	*((long *)(to)) = *((long *)(from))
118*7c478bd9Sstevel@tonic-gate #else
119*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_FILE2HOST(from, to)					\
120*7c478bd9Sstevel@tonic-gate 			    ((char *)(to))[0] = ((char *)(from))[3];	\
121*7c478bd9Sstevel@tonic-gate 			    ((char *)(to))[1] = ((char *)(from))[2];	\
122*7c478bd9Sstevel@tonic-gate 			    ((char *)(to))[2] = ((char *)(from))[1];	\
123*7c478bd9Sstevel@tonic-gate 			    ((char *)(to))[3] = ((char *)(from))[0];
124*7c478bd9Sstevel@tonic-gate #endif /* byte swapping */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64)
127*7c478bd9Sstevel@tonic-gate #define	AUDIO_AU_HOST2FILE(from, to)	AUDIO_AU_FILE2HOST((from), (to))
128*7c478bd9Sstevel@tonic-gate #else
129*7c478bd9Sstevel@tonic-gate #error unknown machine type;
130*7c478bd9Sstevel@tonic-gate #endif /* encode */
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate #endif
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #endif /* _AUDIO_AU_H */
137