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
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.
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]
23 * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _MULTIMEDIA_AUDIO_HDR_H
28 #define _MULTIMEDIA_AUDIO_HDR_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
37 * Define an in-core audio data header.
39 * This is different that the on-disk file header.
40 * The fields defined here are preliminary at best.
44 * The audio header contains the following fields:
46 * endian Byte order of 16-bit or greater PCM,
47 * and possibly floating point data.
49 * sample_rate Number of samples per second (per channel).
51 * samples_per_unit This field describes the number of samples
52 * represented by each sample unit (which, by
53 * definition, are aligned on byte boundaries).
54 * Audio samples may be stored individually
55 * or, in the case of compressed formats
56 * (e.g., ADPCM), grouped in algorithm-
57 * specific ways. If the data is bit-packed,
58 * this field tells the number of samples
59 * needed to get to a byte boundary.
61 * bytes_per_unit Number of bytes stored for each sample unit
63 * channels Number of interleaved sample units.
64 * For any given time quantum, the set
65 * consisting of 'channels' sample units
66 * is called a sample frame. Seeks in
67 * the data should be aligned to the start
68 * of the nearest sample frame.
70 * encoding Data encoding format.
72 * data_size Number of bytes in the data.
73 * This value is advisory only, and may
74 * be set to the value AUDIO_UNKNOWN_SIZE
75 * if the data size is unknown (for
76 * instance, if the data is being
77 * recorded or generated and piped
78 * to another process).
80 * The first four values are used to compute the byte offset given a
81 * particular time, and vice versa. Specifically:
83 * seconds = offset / C
84 * offset = seconds * C
86 * C = (channels * bytes_per_unit * sample_rate) / samples_per_unit
91 unsigned sample_rate
; /* samples per second */
92 unsigned samples_per_unit
; /* samples per unit */
93 unsigned bytes_per_unit
; /* bytes per sample unit */
94 unsigned channels
; /* # of interleaved channels */
95 unsigned encoding
; /* data encoding format */
96 unsigned endian
; /* byte order */
97 unsigned data_size
; /* length of data (optional) */
101 * Define the possible encoding types.
102 * Note that the names that overlap the encodings in <sun/audioio.h>
103 * must have the same values.
105 #define AUDIO_ENCODING_NONE (0) /* No encoding specified ... */
106 #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */
107 #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */
108 #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */
109 #define AUDIO_ENCODING_FLOAT (100) /* IEEE float (-1. <-> +1.) */
110 #define AUDIO_ENCODING_G721 (101) /* CCITT g.721 ADPCM */
111 #define AUDIO_ENCODING_G722 (102) /* CCITT g.722 ADPCM */
112 #define AUDIO_ENCODING_G723 (103) /* CCITT g.723 ADPCM */
113 #define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */
116 * Define the possible endian types.
118 #define AUDIO_ENDIAN_BIG 0 /* SPARC, 68000, etc. */
119 #define AUDIO_ENDIAN_SMALL 1 /* Intel */
120 #define AUDIO_ENDIAN_UNKNOWN 2 /* Unknown endian */
122 /* Value used for indeterminate size (e.g., data passed through a pipe) */
123 #define AUDIO_UNKNOWN_SIZE ((unsigned)(~0))
126 /* Define conversion macros for integer<->floating-point conversions */
128 /* double to 8,16,32-bit linear */
129 #define audio_d2c(X) ((X) >= 1. ? 127 : (X) <= -1. ? -127 : \
130 (char)(rint((X) * 127.)))
131 #define audio_d2s(X) ((X) >= 1. ? 32767 : (X) <= -1. ? -32767 :\
132 (short)(rint((X) * 32767.)))
133 #define audio_d2l(X) ((X) >= 1. ? 2147483647 : (X) <= -1. ? \
135 (long)(rint((X) * 2147483647.)))
137 /* 8,16,32-bit linear to double */
138 #define audio_c2d(X) (((unsigned char)(X)) == 0x80 ? -1. : \
139 ((double)((char)(X))) / 127.)
140 #define audio_s2d(X) (((unsigned short)(X)) == 0x8000 ? -1. :\
141 ((double)((short)(X))) / 32767.)
142 #define audio_l2d(X) (((unsigned long)(X)) == 0x80000000 ? -1. :\
143 ((double)((long)(X))) / 2147483647.)
149 #endif /* !_MULTIMEDIA_AUDIO_HDR_H */