1 #ifndef HAVE_SNDIO
2 /*
3  * SoX bit-rot detection file, obtained from:
4  * http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libsndio/sndio.h
5  */
6 #if defined __GNUC__
7   #pragma GCC system_header
8 #endif
9 
10 /*	$OpenBSD: sndio.h,v 1.7 2009/02/03 19:44:58 ratchov Exp $	*/
11 /*
12  * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
13  *
14  * Permission to use, copy, modify, and distribute this software for any
15  * purpose with or without fee is hereby granted, provided that the above
16  * copyright notice and this permission notice appear in all copies.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
19  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
21  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
24  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25  */
26 #ifndef SNDIO_H
27 #define SNDIO_H
28 
29 #include <sys/param.h>
30 
31 /*
32  * private ``handle'' structure
33  */
34 struct sio_hdl;
35 
36 /*
37  * parameters of a full-duplex stream
38  */
39 struct sio_par {
40 	unsigned bits;		/* bits per sample */
41 	unsigned bps;		/* bytes per sample */
42 	unsigned sig;		/* 1 = signed, 0 = unsigned */
43 	unsigned le;		/* 1 = LE, 0 = BE byte order */
44 	unsigned msb;		/* 1 = MSB, 0 = LSB aligned */
45 	unsigned rchan;		/* number channels for recording direction */
46 	unsigned pchan;		/* number channels for playback direction */
47 	unsigned rate;		/* frames per second */
48 	unsigned bufsz;		/* end-to-end buffer size */
49 #define SIO_IGNORE	0	/* pause during xrun */
50 #define SIO_SYNC	1	/* resync after xrun */
51 #define SIO_ERROR	2	/* terminate on xrun */
52 	unsigned xrun;		/* what to do on overruns/underruns */
53 	unsigned round;		/* optimal bufsz divisor */
54 	unsigned appbufsz;	/* minimum buffer size */
55 	int __pad[3];		/* for future use */
56 	int __magic;		/* for internal/debug purposes only */
57 };
58 
59 /*
60  * capabilities of a stream
61  */
62 struct sio_cap {
63 #define SIO_NENC	8
64 #define SIO_NCHAN	8
65 #define SIO_NRATE	16
66 #define SIO_NCONF	4
67 	struct sio_enc {			/* allowed sample encodings */
68 		unsigned bits;
69 		unsigned bps;
70 		unsigned sig;
71 		unsigned le;
72 		unsigned msb;
73 	} enc[SIO_NENC];
74 	unsigned rchan[SIO_NCHAN];	/* allowed values for rchan */
75 	unsigned pchan[SIO_NCHAN];	/* allowed values for pchan */
76 	unsigned rate[SIO_NRATE];	/* allowed rates */
77 	int __pad[7];			/* for future use */
78 	unsigned nconf;			/* number of elements in confs[] */
79 	struct sio_conf {
80 		unsigned enc;		/* mask of enc[] indexes */
81 		unsigned rchan;		/* mask of chan[] indexes (rec) */
82 		unsigned pchan;		/* mask of chan[] indexes (play) */
83 		unsigned rate;		/* mask of rate[] indexes */
84 	} confs[SIO_NCONF];
85 };
86 
87 #define SIO_XSTRINGS { "ignore", "sync", "error" }
88 
89 /*
90  * mode bitmap
91  */
92 #define SIO_PLAY	1
93 #define SIO_REC		2
94 
95 /*
96  * maximum size of the encording string (the longest possible
97  * encoding is ``s24le3msb'')
98  */
99 #define SIO_ENCMAX	10
100 
101 /*
102  * default bytes per sample for the given bits per sample
103  */
104 #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
105 
106 /*
107  * default value of "sio_par->le" flag
108  */
109 #if BYTE_ORDER == LITTLE_ENDIAN
110 #define SIO_LE_NATIVE 1
111 #else
112 #define SIO_LE_NATIVE 0
113 #endif
114 
115 /*
116  * default device for the sun audio(4) back-end
117  */
118 #define SIO_SUN_PATH	"/dev/audio"
119 
120 /*
121  * default socket name for the aucat(1) back-end
122  */
123 #define SIO_AUCAT_PATH	"default"
124 
125 /*
126  * maximum value of volume, eg. for sio_setvol()
127  */
128 #define SIO_MAXVOL 127
129 
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133 
134 int sio_strtoenc(struct sio_par *, char *);
135 int sio_enctostr(struct sio_par *, char *);
136 void sio_initpar(struct sio_par *);
137 
138 struct sio_hdl *sio_open(char *, unsigned, int);
139 void sio_close(struct sio_hdl *);
140 int sio_setpar(struct sio_hdl *, struct sio_par *);
141 int sio_getpar(struct sio_hdl *, struct sio_par *);
142 int sio_getcap(struct sio_hdl *, struct sio_cap *);
143 void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
144 size_t sio_write(struct sio_hdl *, void *, size_t);
145 size_t sio_read(struct sio_hdl *, void *, size_t);
146 int sio_start(struct sio_hdl *);
147 int sio_stop(struct sio_hdl *);
148 int sio_nfds(struct sio_hdl *);
149 int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
150 int sio_revents(struct sio_hdl *, struct pollfd *);
151 int sio_eof(struct sio_hdl *);
152 int sio_setvol(struct sio_hdl *, unsigned);
153 void sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *);
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif /* !defined(SNDIO_H) */
160 #endif
161