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