| 1 | /* $OpenBSD$ */ |
| 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 | #define SIOCTL_NAMEMAX 12 /* max name length */ |
| 32 | |
| 33 | /* |
| 34 | * private ``handle'' structure |
| 35 | */ |
| 36 | struct sio_hdl; |
| 37 | struct mio_hdl; |
| 38 | struct sioctl_hdl; |
| 39 | |
| 40 | /* |
| 41 | * parameters of a full-duplex stream |
| 42 | */ |
| 43 | struct sio_par { |
| 44 | unsigned int bits; /* bits per sample */ |
| 45 | unsigned int bps; /* bytes per sample */ |
| 46 | unsigned int sig; /* 1 = signed, 0 = unsigned */ |
| 47 | unsigned int le; /* 1 = LE, 0 = BE byte order */ |
| 48 | unsigned int msb; /* 1 = MSB, 0 = LSB aligned */ |
| 49 | unsigned int rchan; /* number channels for recording direction */ |
| 50 | unsigned int pchan; /* number channels for playback direction */ |
| 51 | unsigned int rate; /* frames per second */ |
| 52 | unsigned int bufsz; /* end-to-end buffer size */ |
| 53 | #define SIO_IGNORE 0 /* pause during xrun */ |
| 54 | #define SIO_SYNC 1 /* resync after xrun */ |
| 55 | #define SIO_ERROR 2 /* terminate on xrun */ |
| 56 | unsigned int xrun; /* what to do on overruns/underruns */ |
| 57 | unsigned int round; /* optimal bufsz divisor */ |
| 58 | unsigned int appbufsz; /* minimum buffer size */ |
| 59 | int __pad[3]; /* for future use */ |
| 60 | unsigned int __magic; /* for internal/debug purposes only */ |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * capabilities of a stream |
| 65 | */ |
| 66 | struct sio_cap { |
| 67 | #define SIO_NENC 8 |
| 68 | #define SIO_NCHAN 8 |
| 69 | #define SIO_NRATE 16 |
| 70 | #define SIO_NCONF 4 |
| 71 | struct sio_enc { /* allowed sample encodings */ |
| 72 | unsigned int bits; |
| 73 | unsigned int bps; |
| 74 | unsigned int sig; |
| 75 | unsigned int le; |
| 76 | unsigned int msb; |
| 77 | } enc[SIO_NENC]; |
| 78 | unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */ |
| 79 | unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */ |
| 80 | unsigned int rate[SIO_NRATE]; /* allowed rates */ |
| 81 | int __pad[7]; /* for future use */ |
| 82 | unsigned int nconf; /* number of elements in confs[] */ |
| 83 | struct sio_conf { |
| 84 | unsigned int enc; /* mask of enc[] indexes */ |
| 85 | unsigned int rchan; /* mask of chan[] indexes (rec) */ |
| 86 | unsigned int pchan; /* mask of chan[] indexes (play) */ |
| 87 | unsigned int rate; /* mask of rate[] indexes */ |
| 88 | } confs[SIO_NCONF]; |
| 89 | }; |
| 90 | |
| 91 | #define SIO_XSTRINGS { "ignore", "sync", "error" } |
| 92 | |
| 93 | /* |
| 94 | * controlled component of the device |
| 95 | */ |
| 96 | struct sioctl_node { |
| 97 | char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */ |
| 98 | int unit; /* optional number or -1 */ |
| 99 | }; |
| 100 | |
| 101 | /* |
| 102 | * description of a control (index, value) pair |
| 103 | */ |
| 104 | struct sioctl_desc { |
| 105 | unsigned int addr; /* control address */ |
| 106 | #define SIOCTL_NONE 0 /* deleted */ |
| 107 | #define SIOCTL_NUM 2 /* integer in the 0..maxval range */ |
| 108 | #define SIOCTL_SW 3 /* on/off switch (0 or 1) */ |
| 109 | #define SIOCTL_VEC 4 /* number, element of vector */ |
| 110 | #define SIOCTL_LIST 5 /* switch, element of a list */ |
| 111 | #define SIOCTL_SEL 6 /* element of a selector */ |
| 112 | unsigned int type; /* one of above */ |
| 113 | char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */ |
| 114 | char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ |
| 115 | struct sioctl_node node0; /* affected node */ |
| 116 | struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST,SEL} */ |
| 117 | unsigned int maxval; /* max value */ |
| 118 | int __pad[3]; |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * mode bitmap |
| 123 | */ |
| 124 | #define SIO_PLAY 1 |
| 125 | #define SIO_REC 2 |
| 126 | #define MIO_OUT 4 |
| 127 | #define MIO_IN 8 |
| 128 | #define SIOCTL_READ 0x100 |
| 129 | #define SIOCTL_WRITE 0x200 |
| 130 | |
| 131 | /* |
| 132 | * default bytes per sample for the given bits per sample |
| 133 | */ |
| 134 | #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) |
| 135 | |
| 136 | /* |
| 137 | * default value of "sio_par->le" flag |
| 138 | */ |
| 139 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 140 | #define SIO_LE_NATIVE 1 |
| 141 | #else |
| 142 | #define SIO_LE_NATIVE 0 |
| 143 | #endif |
| 144 | |
| 145 | /* |
| 146 | * maximum value of volume, eg. for sio_setvol() |
| 147 | */ |
| 148 | #define SIO_MAXVOL 127 |
| 149 | |
| 150 | #ifdef __cplusplus |
| 151 | extern "C" { |
| 152 | #endif |
| 153 | |
| 154 | struct pollfd; |
| 155 | |
| 156 | void sio_initpar(struct sio_par *); |
| 157 | struct sio_hdl *sio_open(const char *, unsigned int, int); |
| 158 | void sio_close(struct sio_hdl *); |
| 159 | int sio_setpar(struct sio_hdl *, struct sio_par *); |
| 160 | int sio_getpar(struct sio_hdl *, struct sio_par *); |
| 161 | int sio_getcap(struct sio_hdl *, struct sio_cap *); |
| 162 | void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); |
| 163 | size_t sio_write(struct sio_hdl *, const void *, size_t); |
| 164 | size_t sio_read(struct sio_hdl *, void *, size_t); |
| 165 | int sio_start(struct sio_hdl *); |
| 166 | int sio_stop(struct sio_hdl *); |
| 167 | int sio_nfds(struct sio_hdl *); |
| 168 | int sio_pollfd(struct sio_hdl *, struct pollfd *, int); |
| 169 | int sio_revents(struct sio_hdl *, struct pollfd *); |
| 170 | int sio_eof(struct sio_hdl *); |
| 171 | int sio_setvol(struct sio_hdl *, unsigned int); |
| 172 | int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *); |
| 173 | |
| 174 | struct mio_hdl *mio_open(const char *, unsigned int, int); |
| 175 | void mio_close(struct mio_hdl *); |
| 176 | size_t mio_write(struct mio_hdl *, const void *, size_t); |
| 177 | size_t mio_read(struct mio_hdl *, void *, size_t); |
| 178 | int mio_nfds(struct mio_hdl *); |
| 179 | int mio_pollfd(struct mio_hdl *, struct pollfd *, int); |
| 180 | int mio_revents(struct mio_hdl *, struct pollfd *); |
| 181 | int mio_eof(struct mio_hdl *); |
| 182 | |
| 183 | struct sioctl_hdl *sioctl_open(const char *, unsigned int, int); |
| 184 | void sioctl_close(struct sioctl_hdl *); |
| 185 | int sioctl_ondesc(struct sioctl_hdl *, |
| 186 | void (*)(void *, struct sioctl_desc *, int), void *); |
| 187 | int sioctl_onval(struct sioctl_hdl *, |
| 188 | void (*)(void *, unsigned int, unsigned int), void *); |
| 189 | int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int); |
| 190 | int sioctl_nfds(struct sioctl_hdl *); |
| 191 | int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int); |
| 192 | int sioctl_revents(struct sioctl_hdl *, struct pollfd *); |
| 193 | int sioctl_eof(struct sioctl_hdl *); |
| 194 | |
| 195 | int mio_rmidi_getfd(const char *, unsigned int, int); |
| 196 | struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int); |
| 197 | int sio_sun_getfd(const char *, unsigned int, int); |
| 198 | struct sio_hdl *sio_sun_fdopen(int, unsigned int, int); |
| 199 | int sioctl_sun_getfd(const char *, unsigned int, int); |
| 200 | struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int); |
| 201 | |
| 202 | #ifdef __cplusplus |
| 203 | } |
| 204 | #endif |
| 205 | |
| 206 | #endif /* !defined(SNDIO_H) */ |
| 207 | |