libaudio.h revision 1.1 1 /* $NetBSD: libaudio.h,v 1.1 1999/03/26 14:02:40 mrg Exp $ */
2
3
4 /*
5 * We copy the Sun/NeXT on-disk audio header format and document what
6 * we know of it here.
7 *
8 * The header size appears to be an offset to where the data really
9 * begins, rather than defining the real length of the audio header.
10 * The Sun/NeXT audio format seems to only use 24 bytes of data (with
11 * an additional 8 bytes of nuls written, padding it to 32 bytes).
12 *
13 * If the size of the audio data is unknown (eg, reading from a pipe)
14 * the Sun demo audio tools place AUDIO_UNKNOWN_SIZE in the
15 * `data_size' member.
16 *
17 * For stereo data, the channels appear to be interleaved with the
18 * left channel first. For more channels, who knows?
19 */
20
21 /*
22 * This is the Sun/NeXT audio file magic value. Note that it
23 * is also `.snd' in ASCII.
24 */
25 #define AUDIO_FILE_MAGIC ((u_int32_t)0x2e736e64)
26 #define AUDIO_UNKNOWN_SIZE ((unsigned)(~0))
27
28 typedef struct {
29 u_int32_t magic;
30 u_int32_t hdr_size; /* header size; in bytes */
31 u_int32_t data_size; /* optional; in bytes */
32 u_int32_t encoding; /* see below */
33 u_int32_t sample_rate; /* per second */
34 u_int32_t channels; /* number of interleaved channels */
35 } sun_audioheader;
36
37 #define Audio_filehdr sun_audioheader /* SunOS compat(?) */
38
39 /*
40 * these are the types of "encoding" for above. taken from the
41 * SunOS <multimedia/audio_filehdr.h>.
42 */
43 #define AUDIO_FILE_ENCODING_MULAW_8 1
44 #define AUDIO_FILE_ENCODING_LINEAR_8 2
45 #define AUDIO_FILE_ENCODING_LINEAR_16 3
46 #define AUDIO_FILE_ENCODING_LINEAR_24 4
47 #define AUDIO_FILE_ENCODING_LINEAR_32 5
48 #define AUDIO_FILE_ENCODING_FLOAT 6
49 #define AUDIO_FILE_ENCODING_DOUBLE 7
50 #define AUDIO_FILE_ENCODING_ADPCM_G721 23
51 #define AUDIO_FILE_ENCODING_ADPCM_G722 24
52 #define AUDIO_FILE_ENCODING_ADPCM_G723_3 25
53 #define AUDIO_FILE_ENCODING_ADPCM_G723_5 26
54 #define AUDIO_FILE_ENCODING_ALAW_8 27
55
56 char *audio_enc_from_val __P((int));
57 int audio_enc_to_val __P((const char *));
58
59 int audio_get_sun_encoding __P((int, int *, int *));
60
61 /*
62 * M$ WAV files, info gleamed from sox sources
63 */
64
65 /*
66 * This is the WAV audio file magic value. Note that it
67 * is also `RIFF' and `WAVE' in ASCII.
68 */
69 #define WAVAUDIO_FILE_MAGIC_RIFF ((u_int32_t)0x52494646)
70 #define WAVAUDIO_FILE_MAGIC_WAVE ((u_int32_t)0x57415645)
71 #define WAVAUDIO_FILE_MAGIC_FMT ((u_int32_t)0x666d7420)
72 #define WAVAUDIO_FILE_MAGIC_DATA ((u_int32_t)0x64617461)
73
74 /* purloined from public Microsoft RIFF docs via sox */
75 #define WAVE_FORMAT_UNKNOWN (0x0000)
76 #define WAVE_FORMAT_PCM (0x0001)
77 #define WAVE_FORMAT_ADPCM (0x0002)
78 #define WAVE_FORMAT_ALAW (0x0006)
79 #define WAVE_FORMAT_MULAW (0x0007)
80 #define WAVE_FORMAT_OKI_ADPCM (0x0010)
81 #define WAVE_FORMAT_DIGISTD (0x0015)
82 #define WAVE_FORMAT_DIGIFIX (0x0016)
83 #define IBM_FORMAT_MULAW (0x0101)
84 #define IBM_FORMAT_ALAW (0x0102)
85 #define IBM_FORMAT_ADPCM (0x0103)
86
87 typedef struct {
88 char name[4];
89 u_int32_t len;
90 } wav_audioheaderpart;
91
92 typedef struct {
93 u_int16_t tag;
94 u_int16_t channels;
95 u_int32_t sample_rate;
96 u_int32_t avg_bps;
97 u_int16_t alignment;
98 u_int16_t bits_per_sample;
99 } wav_audioheaderfmt __attribute__((__packed__));
100
101 /* returns size of header, or -1 */
102 size_t audio_parse_wav_hdr __P((void *, size_t, int *, int *, int *, int *));
103
104 /*
105 * audio routine error codes
106 */
107 #define AUDIO_ENOENT -1 /* no such audio format */
108 #define AUDIO_ESHORTHDR -2 /* short header */
109 #define AUDIO_EWAVUNSUPP -3 /* WAV: unsupported file */
110 #define AUDIO_EWAVBADPCM -4 /* WAV: bad PCM bps */
111 #define AUDIO_EWAVNODATA -5 /* WAV: missing data */
112
113 #define AUDIO_MAXERRNO 5
114
115 /* and something to get a string associated with this error */
116 const char *audio_errstring __P((int));
117
118 int audio_parse_encoding __P((char *, int, int *, int *));
119
120 /*
121 * generic routines?
122 */
123 void decode_int __P((const char *, int *));
124 void decode_time __P((const char *, struct timeval *));
125 void decode_encoding __P((const char *, int *));
126
127 /*
128 * get/put 16/32 bits of big/little endian data
129 */
130 #include <sys/types.h>
131 #include <machine/endian.h>
132 #include <machine/bswap.h>
133
134 #if BYTE_ORDER == BIG_ENDIAN
135
136 #define getle16(v) bswap16(v)
137 #define getle32(v) bswap32(v)
138 #define getbe16(v) (v)
139 #define getbe32(v) (v)
140
141 #define putle16(v) bswap16(v)
142 #define putle32(v) bswap32(v)
143 #define putbe16(v) (v)
144 #define putbe32(v) (v)
145
146 #else
147
148 #define getle16(v) (v)
149 #define getle32(v) (v)
150 #define getbe16(v) bswap16(v)
151 #define getbe32(v) bswap32(v)
152
153 #define putle16(v) (v)
154 #define putle32(v) (v)
155 #define putbe16(v) bswap16(v)
156 #define putbe32(v) bswap32(v)
157
158 #endif
159