1 /* $OpenBSD: sndio.h,v 1.15 2024/05/24 15:10:26 ratchov Exp $ */ 2 /* 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 #ifndef SNDIO_H 18 #define SNDIO_H 19 20 #include <sys/types.h> 21 22 /* 23 * default audio device and MIDI port 24 */ 25 #define SIO_DEVANY "default" 26 #define MIO_PORTANY "default" 27 28 /* 29 * limits 30 * 31 * For now SIOCTL_DISPLAYMAX is 12 byte only. It nicely fits in the 32 * padding of the sioctl_desc structure: this allows any binary linked 33 * to the library version with no sioctl_desc->display to work with 34 * this library version. Currently, any string reported by the lower 35 * layers fits in the 12-byte buffer. Once larger strings start 36 * being used (or the ABI changes for any other reason) increase 37 * SIOCTL_DISPLAYMAX and properly pad the sioctl_desc structure. 38 */ 39 #define SIOCTL_NAMEMAX 12 /* max name length */ 40 #define SIOCTL_DISPLAYMAX 12 /* max display string length */ 41 42 /* 43 * private ``handle'' structure 44 */ 45 struct sio_hdl; 46 struct mio_hdl; 47 struct sioctl_hdl; 48 49 /* 50 * parameters of a full-duplex stream 51 */ 52 struct sio_par { 53 unsigned int bits; /* bits per sample */ 54 unsigned int bps; /* bytes per sample */ 55 unsigned int sig; /* 1 = signed, 0 = unsigned */ 56 unsigned int le; /* 1 = LE, 0 = BE byte order */ 57 unsigned int msb; /* 1 = MSB, 0 = LSB aligned */ 58 unsigned int rchan; /* number channels for recording direction */ 59 unsigned int pchan; /* number channels for playback direction */ 60 unsigned int rate; /* frames per second */ 61 unsigned int bufsz; /* end-to-end buffer size */ 62 #define SIO_IGNORE 0 /* pause during xrun */ 63 #define SIO_SYNC 1 /* resync after xrun */ 64 #define SIO_ERROR 2 /* terminate on xrun */ 65 unsigned int xrun; /* what to do on overruns/underruns */ 66 unsigned int round; /* optimal bufsz divisor */ 67 unsigned int appbufsz; /* minimum buffer size */ 68 int __pad[3]; /* for future use */ 69 unsigned int __magic; /* for internal/debug purposes only */ 70 }; 71 72 /* 73 * capabilities of a stream 74 */ 75 struct sio_cap { 76 #define SIO_NENC 8 77 #define SIO_NCHAN 8 78 #define SIO_NRATE 16 79 #define SIO_NCONF 4 80 struct sio_enc { /* allowed sample encodings */ 81 unsigned int bits; 82 unsigned int bps; 83 unsigned int sig; 84 unsigned int le; 85 unsigned int msb; 86 } enc[SIO_NENC]; 87 unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */ 88 unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */ 89 unsigned int rate[SIO_NRATE]; /* allowed rates */ 90 int __pad[7]; /* for future use */ 91 unsigned int nconf; /* number of elements in confs[] */ 92 struct sio_conf { 93 unsigned int enc; /* mask of enc[] indexes */ 94 unsigned int rchan; /* mask of chan[] indexes (rec) */ 95 unsigned int pchan; /* mask of chan[] indexes (play) */ 96 unsigned int rate; /* mask of rate[] indexes */ 97 } confs[SIO_NCONF]; 98 }; 99 100 #define SIO_XSTRINGS { "ignore", "sync", "error" } 101 102 /* 103 * controlled component of the device 104 */ 105 struct sioctl_node { 106 char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */ 107 int unit; /* optional number or -1 */ 108 }; 109 110 /* 111 * description of a control (index, value) pair 112 */ 113 struct sioctl_desc { 114 unsigned int addr; /* control address */ 115 #define SIOCTL_NONE 0 /* deleted */ 116 #define SIOCTL_NUM 2 /* integer in the 0..maxval range */ 117 #define SIOCTL_SW 3 /* on/off switch (0 or 1) */ 118 #define SIOCTL_VEC 4 /* number, element of vector */ 119 #define SIOCTL_LIST 5 /* switch, element of a list */ 120 #define SIOCTL_SEL 6 /* element of a selector */ 121 unsigned int type; /* one of above */ 122 char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */ 123 char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ 124 struct sioctl_node node0; /* affected node */ 125 struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST,SEL} */ 126 unsigned int maxval; /* max value */ 127 char display[SIOCTL_DISPLAYMAX]; /* free-format hint */ 128 }; 129 130 /* 131 * mode bitmap 132 */ 133 #define SIO_PLAY 1 134 #define SIO_REC 2 135 #define MIO_OUT 4 136 #define MIO_IN 8 137 #define SIOCTL_READ 0x100 138 #define SIOCTL_WRITE 0x200 139 140 /* 141 * default bytes per sample for the given bits per sample 142 */ 143 #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) 144 145 /* 146 * default value of "sio_par->le" flag 147 */ 148 #if BYTE_ORDER == LITTLE_ENDIAN 149 #define SIO_LE_NATIVE 1 150 #else 151 #define SIO_LE_NATIVE 0 152 #endif 153 154 /* 155 * maximum value of volume, eg. for sio_setvol() 156 */ 157 #define SIO_MAXVOL 127 158 159 #ifdef __cplusplus 160 extern "C" { 161 #endif 162 163 struct pollfd; 164 165 void sio_initpar(struct sio_par *); 166 struct sio_hdl *sio_open(const char *, unsigned int, int); 167 void sio_close(struct sio_hdl *); 168 int sio_setpar(struct sio_hdl *, struct sio_par *); 169 int sio_getpar(struct sio_hdl *, struct sio_par *); 170 int sio_getcap(struct sio_hdl *, struct sio_cap *); 171 void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); 172 size_t sio_write(struct sio_hdl *, const void *, size_t); 173 size_t sio_read(struct sio_hdl *, void *, size_t); 174 int sio_start(struct sio_hdl *); 175 int sio_stop(struct sio_hdl *); 176 int sio_flush(struct sio_hdl *); 177 int sio_nfds(struct sio_hdl *); 178 int sio_pollfd(struct sio_hdl *, struct pollfd *, int); 179 int sio_revents(struct sio_hdl *, struct pollfd *); 180 int sio_eof(struct sio_hdl *); 181 int sio_setvol(struct sio_hdl *, unsigned int); 182 int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *); 183 184 struct mio_hdl *mio_open(const char *, unsigned int, int); 185 void mio_close(struct mio_hdl *); 186 size_t mio_write(struct mio_hdl *, const void *, size_t); 187 size_t mio_read(struct mio_hdl *, void *, size_t); 188 int mio_nfds(struct mio_hdl *); 189 int mio_pollfd(struct mio_hdl *, struct pollfd *, int); 190 int mio_revents(struct mio_hdl *, struct pollfd *); 191 int mio_eof(struct mio_hdl *); 192 193 struct sioctl_hdl *sioctl_open(const char *, unsigned int, int); 194 void sioctl_close(struct sioctl_hdl *); 195 int sioctl_ondesc(struct sioctl_hdl *, 196 void (*)(void *, struct sioctl_desc *, int), void *); 197 int sioctl_onval(struct sioctl_hdl *, 198 void (*)(void *, unsigned int, unsigned int), void *); 199 int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int); 200 int sioctl_nfds(struct sioctl_hdl *); 201 int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int); 202 int sioctl_revents(struct sioctl_hdl *, struct pollfd *); 203 int sioctl_eof(struct sioctl_hdl *); 204 205 int mio_rmidi_getfd(const char *, unsigned int, int); 206 struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int); 207 int sio_sun_getfd(const char *, unsigned int, int); 208 struct sio_hdl *sio_sun_fdopen(int, unsigned int, int); 209 int sioctl_sun_getfd(const char *, unsigned int, int); 210 struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int); 211 212 #ifdef __cplusplus 213 } 214 #endif 215 216 #endif /* !defined(SNDIO_H) */ 217