1*ec8a3410Sratchov /* $OpenBSD: sndio.h,v 1.14 2022/04/29 08:30:48 ratchov Exp $ */ 2fcb16ac0Sratchov /* 3fcb16ac0Sratchov * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4fcb16ac0Sratchov * 5fcb16ac0Sratchov * Permission to use, copy, modify, and distribute this software for any 6fcb16ac0Sratchov * purpose with or without fee is hereby granted, provided that the above 7fcb16ac0Sratchov * copyright notice and this permission notice appear in all copies. 8fcb16ac0Sratchov * 9fcb16ac0Sratchov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10fcb16ac0Sratchov * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11fcb16ac0Sratchov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12fcb16ac0Sratchov * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13fcb16ac0Sratchov * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14fcb16ac0Sratchov * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15fcb16ac0Sratchov * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16fcb16ac0Sratchov */ 17fcb16ac0Sratchov #ifndef SNDIO_H 18fcb16ac0Sratchov #define SNDIO_H 19fcb16ac0Sratchov 207690362dSratchov #include <sys/types.h> 21fcb16ac0Sratchov 22fcb16ac0Sratchov /* 239f9aa69fSratchov * default audio device and MIDI port 249f9aa69fSratchov */ 259f9aa69fSratchov #define SIO_DEVANY "default" 269f9aa69fSratchov #define MIO_PORTANY "default" 279f9aa69fSratchov 289f9aa69fSratchov /* 29d07fece6Sratchov * limits 30d07fece6Sratchov */ 31d07fece6Sratchov #define SIOCTL_NAMEMAX 12 /* max name length */ 32d07fece6Sratchov 33d07fece6Sratchov /* 34fcb16ac0Sratchov * private ``handle'' structure 35fcb16ac0Sratchov */ 36fcb16ac0Sratchov struct sio_hdl; 376efede29Sratchov struct mio_hdl; 38d07fece6Sratchov struct sioctl_hdl; 39fcb16ac0Sratchov 40fcb16ac0Sratchov /* 41fcb16ac0Sratchov * parameters of a full-duplex stream 42fcb16ac0Sratchov */ 43fcb16ac0Sratchov struct sio_par { 447207b069Sratchov unsigned int bits; /* bits per sample */ 457207b069Sratchov unsigned int bps; /* bytes per sample */ 467207b069Sratchov unsigned int sig; /* 1 = signed, 0 = unsigned */ 477207b069Sratchov unsigned int le; /* 1 = LE, 0 = BE byte order */ 487207b069Sratchov unsigned int msb; /* 1 = MSB, 0 = LSB aligned */ 497207b069Sratchov unsigned int rchan; /* number channels for recording direction */ 507207b069Sratchov unsigned int pchan; /* number channels for playback direction */ 517207b069Sratchov unsigned int rate; /* frames per second */ 527207b069Sratchov unsigned int bufsz; /* end-to-end buffer size */ 53fcb16ac0Sratchov #define SIO_IGNORE 0 /* pause during xrun */ 54fcb16ac0Sratchov #define SIO_SYNC 1 /* resync after xrun */ 55fcb16ac0Sratchov #define SIO_ERROR 2 /* terminate on xrun */ 567207b069Sratchov unsigned int xrun; /* what to do on overruns/underruns */ 577207b069Sratchov unsigned int round; /* optimal bufsz divisor */ 587207b069Sratchov unsigned int appbufsz; /* minimum buffer size */ 59fcb16ac0Sratchov int __pad[3]; /* for future use */ 60493ea524Sespie unsigned int __magic; /* for internal/debug purposes only */ 61fcb16ac0Sratchov }; 62fcb16ac0Sratchov 63fcb16ac0Sratchov /* 64fcb16ac0Sratchov * capabilities of a stream 65fcb16ac0Sratchov */ 66fcb16ac0Sratchov struct sio_cap { 67fcb16ac0Sratchov #define SIO_NENC 8 68fcb16ac0Sratchov #define SIO_NCHAN 8 69fcb16ac0Sratchov #define SIO_NRATE 16 70fcb16ac0Sratchov #define SIO_NCONF 4 71fcb16ac0Sratchov struct sio_enc { /* allowed sample encodings */ 727207b069Sratchov unsigned int bits; 737207b069Sratchov unsigned int bps; 747207b069Sratchov unsigned int sig; 757207b069Sratchov unsigned int le; 767207b069Sratchov unsigned int msb; 77fcb16ac0Sratchov } enc[SIO_NENC]; 787207b069Sratchov unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */ 797207b069Sratchov unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */ 807207b069Sratchov unsigned int rate[SIO_NRATE]; /* allowed rates */ 81fcb16ac0Sratchov int __pad[7]; /* for future use */ 827207b069Sratchov unsigned int nconf; /* number of elements in confs[] */ 83fcb16ac0Sratchov struct sio_conf { 847207b069Sratchov unsigned int enc; /* mask of enc[] indexes */ 857207b069Sratchov unsigned int rchan; /* mask of chan[] indexes (rec) */ 867207b069Sratchov unsigned int pchan; /* mask of chan[] indexes (play) */ 877207b069Sratchov unsigned int rate; /* mask of rate[] indexes */ 88fcb16ac0Sratchov } confs[SIO_NCONF]; 89fcb16ac0Sratchov }; 90fcb16ac0Sratchov 91fcb16ac0Sratchov #define SIO_XSTRINGS { "ignore", "sync", "error" } 92fcb16ac0Sratchov 93fcb16ac0Sratchov /* 94d07fece6Sratchov * controlled component of the device 95d07fece6Sratchov */ 96d07fece6Sratchov struct sioctl_node { 97d07fece6Sratchov char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */ 98d07fece6Sratchov int unit; /* optional number or -1 */ 99d07fece6Sratchov }; 100d07fece6Sratchov 101d07fece6Sratchov /* 102d07fece6Sratchov * description of a control (index, value) pair 103d07fece6Sratchov */ 104d07fece6Sratchov struct sioctl_desc { 105d07fece6Sratchov unsigned int addr; /* control address */ 106d07fece6Sratchov #define SIOCTL_NONE 0 /* deleted */ 107433bc805Sratchov #define SIOCTL_NUM 2 /* integer in the 0..maxval range */ 108d07fece6Sratchov #define SIOCTL_SW 3 /* on/off switch (0 or 1) */ 109d07fece6Sratchov #define SIOCTL_VEC 4 /* number, element of vector */ 110d07fece6Sratchov #define SIOCTL_LIST 5 /* switch, element of a list */ 11149f67e12Sratchov #define SIOCTL_SEL 6 /* element of a selector */ 112d07fece6Sratchov unsigned int type; /* one of above */ 113d07fece6Sratchov char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */ 114d07fece6Sratchov char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ 115d07fece6Sratchov struct sioctl_node node0; /* affected node */ 11649f67e12Sratchov struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST,SEL} */ 117433bc805Sratchov unsigned int maxval; /* max value */ 118d07fece6Sratchov int __pad[3]; 119d07fece6Sratchov }; 120d07fece6Sratchov 121d07fece6Sratchov /* 122fcb16ac0Sratchov * mode bitmap 123fcb16ac0Sratchov */ 124fcb16ac0Sratchov #define SIO_PLAY 1 125fcb16ac0Sratchov #define SIO_REC 2 1266efede29Sratchov #define MIO_OUT 4 1276efede29Sratchov #define MIO_IN 8 128d07fece6Sratchov #define SIOCTL_READ 0x100 129d07fece6Sratchov #define SIOCTL_WRITE 0x200 130fcb16ac0Sratchov 131fcb16ac0Sratchov /* 132fcb16ac0Sratchov * default bytes per sample for the given bits per sample 133fcb16ac0Sratchov */ 134fcb16ac0Sratchov #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) 135fcb16ac0Sratchov 136fcb16ac0Sratchov /* 137fcb16ac0Sratchov * default value of "sio_par->le" flag 138fcb16ac0Sratchov */ 139fcb16ac0Sratchov #if BYTE_ORDER == LITTLE_ENDIAN 140fcb16ac0Sratchov #define SIO_LE_NATIVE 1 141fcb16ac0Sratchov #else 142fcb16ac0Sratchov #define SIO_LE_NATIVE 0 143fcb16ac0Sratchov #endif 144fcb16ac0Sratchov 145fcb16ac0Sratchov /* 146fcb16ac0Sratchov * maximum value of volume, eg. for sio_setvol() 147fcb16ac0Sratchov */ 148fcb16ac0Sratchov #define SIO_MAXVOL 127 149fcb16ac0Sratchov 150fcb16ac0Sratchov #ifdef __cplusplus 151fcb16ac0Sratchov extern "C" { 152fcb16ac0Sratchov #endif 153fcb16ac0Sratchov 154fcb16ac0Sratchov struct pollfd; 155fcb16ac0Sratchov 156fcb16ac0Sratchov void sio_initpar(struct sio_par *); 1577207b069Sratchov struct sio_hdl *sio_open(const char *, unsigned int, int); 158fcb16ac0Sratchov void sio_close(struct sio_hdl *); 159fcb16ac0Sratchov int sio_setpar(struct sio_hdl *, struct sio_par *); 160fcb16ac0Sratchov int sio_getpar(struct sio_hdl *, struct sio_par *); 161fcb16ac0Sratchov int sio_getcap(struct sio_hdl *, struct sio_cap *); 162fcb16ac0Sratchov void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); 163bb957eeeSratchov size_t sio_write(struct sio_hdl *, const void *, size_t); 164fcb16ac0Sratchov size_t sio_read(struct sio_hdl *, void *, size_t); 165fcb16ac0Sratchov int sio_start(struct sio_hdl *); 166fcb16ac0Sratchov int sio_stop(struct sio_hdl *); 167*ec8a3410Sratchov int sio_flush(struct sio_hdl *); 168fcb16ac0Sratchov int sio_nfds(struct sio_hdl *); 169fcb16ac0Sratchov int sio_pollfd(struct sio_hdl *, struct pollfd *, int); 170fcb16ac0Sratchov int sio_revents(struct sio_hdl *, struct pollfd *); 171fcb16ac0Sratchov int sio_eof(struct sio_hdl *); 1727207b069Sratchov int sio_setvol(struct sio_hdl *, unsigned int); 1737207b069Sratchov int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *); 174fcb16ac0Sratchov 1757207b069Sratchov struct mio_hdl *mio_open(const char *, unsigned int, int); 1766efede29Sratchov void mio_close(struct mio_hdl *); 177bb957eeeSratchov size_t mio_write(struct mio_hdl *, const void *, size_t); 1786efede29Sratchov size_t mio_read(struct mio_hdl *, void *, size_t); 1796efede29Sratchov int mio_nfds(struct mio_hdl *); 1806efede29Sratchov int mio_pollfd(struct mio_hdl *, struct pollfd *, int); 1816efede29Sratchov int mio_revents(struct mio_hdl *, struct pollfd *); 1826efede29Sratchov int mio_eof(struct mio_hdl *); 1836efede29Sratchov 184d07fece6Sratchov struct sioctl_hdl *sioctl_open(const char *, unsigned int, int); 185d07fece6Sratchov void sioctl_close(struct sioctl_hdl *); 186d07fece6Sratchov int sioctl_ondesc(struct sioctl_hdl *, 187d07fece6Sratchov void (*)(void *, struct sioctl_desc *, int), void *); 188d07fece6Sratchov int sioctl_onval(struct sioctl_hdl *, 189d07fece6Sratchov void (*)(void *, unsigned int, unsigned int), void *); 190d07fece6Sratchov int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int); 191d07fece6Sratchov int sioctl_nfds(struct sioctl_hdl *); 192d07fece6Sratchov int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int); 193d07fece6Sratchov int sioctl_revents(struct sioctl_hdl *, struct pollfd *); 194d07fece6Sratchov int sioctl_eof(struct sioctl_hdl *); 195d07fece6Sratchov 196bde5d162Sratchov int mio_rmidi_getfd(const char *, unsigned int, int); 197bde5d162Sratchov struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int); 198bde5d162Sratchov int sio_sun_getfd(const char *, unsigned int, int); 199bde5d162Sratchov struct sio_hdl *sio_sun_fdopen(int, unsigned int, int); 200d07fece6Sratchov int sioctl_sun_getfd(const char *, unsigned int, int); 201d07fece6Sratchov struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int); 202bde5d162Sratchov 203fcb16ac0Sratchov #ifdef __cplusplus 204fcb16ac0Sratchov } 205fcb16ac0Sratchov #endif 206fcb16ac0Sratchov 207fcb16ac0Sratchov #endif /* !defined(SNDIO_H) */ 208