1*9f9aa69fSratchov /* $OpenBSD: sndio.h,v 1.6 2012/05/23 19:25:11 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 20fcb16ac0Sratchov #include <sys/param.h> 21fcb16ac0Sratchov 22fcb16ac0Sratchov /* 23*9f9aa69fSratchov * default audio device and MIDI port 24*9f9aa69fSratchov */ 25*9f9aa69fSratchov #define SIO_DEVANY "default" 26*9f9aa69fSratchov #define MIO_PORTANY "default" 27*9f9aa69fSratchov 28*9f9aa69fSratchov /* 29fcb16ac0Sratchov * private ``handle'' structure 30fcb16ac0Sratchov */ 31fcb16ac0Sratchov struct sio_hdl; 326efede29Sratchov struct mio_hdl; 33fcb16ac0Sratchov 34fcb16ac0Sratchov /* 35fcb16ac0Sratchov * parameters of a full-duplex stream 36fcb16ac0Sratchov */ 37fcb16ac0Sratchov struct sio_par { 387207b069Sratchov unsigned int bits; /* bits per sample */ 397207b069Sratchov unsigned int bps; /* bytes per sample */ 407207b069Sratchov unsigned int sig; /* 1 = signed, 0 = unsigned */ 417207b069Sratchov unsigned int le; /* 1 = LE, 0 = BE byte order */ 427207b069Sratchov unsigned int msb; /* 1 = MSB, 0 = LSB aligned */ 437207b069Sratchov unsigned int rchan; /* number channels for recording direction */ 447207b069Sratchov unsigned int pchan; /* number channels for playback direction */ 457207b069Sratchov unsigned int rate; /* frames per second */ 467207b069Sratchov unsigned int bufsz; /* end-to-end buffer size */ 47fcb16ac0Sratchov #define SIO_IGNORE 0 /* pause during xrun */ 48fcb16ac0Sratchov #define SIO_SYNC 1 /* resync after xrun */ 49fcb16ac0Sratchov #define SIO_ERROR 2 /* terminate on xrun */ 507207b069Sratchov unsigned int xrun; /* what to do on overruns/underruns */ 517207b069Sratchov unsigned int round; /* optimal bufsz divisor */ 527207b069Sratchov unsigned int appbufsz; /* minimum buffer size */ 53fcb16ac0Sratchov int __pad[3]; /* for future use */ 54fcb16ac0Sratchov int __magic; /* for internal/debug purposes only */ 55fcb16ac0Sratchov }; 56fcb16ac0Sratchov 57fcb16ac0Sratchov /* 58fcb16ac0Sratchov * capabilities of a stream 59fcb16ac0Sratchov */ 60fcb16ac0Sratchov struct sio_cap { 61fcb16ac0Sratchov #define SIO_NENC 8 62fcb16ac0Sratchov #define SIO_NCHAN 8 63fcb16ac0Sratchov #define SIO_NRATE 16 64fcb16ac0Sratchov #define SIO_NCONF 4 65fcb16ac0Sratchov struct sio_enc { /* allowed sample encodings */ 667207b069Sratchov unsigned int bits; 677207b069Sratchov unsigned int bps; 687207b069Sratchov unsigned int sig; 697207b069Sratchov unsigned int le; 707207b069Sratchov unsigned int msb; 71fcb16ac0Sratchov } enc[SIO_NENC]; 727207b069Sratchov unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */ 737207b069Sratchov unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */ 747207b069Sratchov unsigned int rate[SIO_NRATE]; /* allowed rates */ 75fcb16ac0Sratchov int __pad[7]; /* for future use */ 767207b069Sratchov unsigned int nconf; /* number of elements in confs[] */ 77fcb16ac0Sratchov struct sio_conf { 787207b069Sratchov unsigned int enc; /* mask of enc[] indexes */ 797207b069Sratchov unsigned int rchan; /* mask of chan[] indexes (rec) */ 807207b069Sratchov unsigned int pchan; /* mask of chan[] indexes (play) */ 817207b069Sratchov unsigned int rate; /* mask of rate[] indexes */ 82fcb16ac0Sratchov } confs[SIO_NCONF]; 83fcb16ac0Sratchov }; 84fcb16ac0Sratchov 85fcb16ac0Sratchov #define SIO_XSTRINGS { "ignore", "sync", "error" } 86fcb16ac0Sratchov 87fcb16ac0Sratchov /* 88fcb16ac0Sratchov * mode bitmap 89fcb16ac0Sratchov */ 90fcb16ac0Sratchov #define SIO_PLAY 1 91fcb16ac0Sratchov #define SIO_REC 2 926efede29Sratchov #define MIO_OUT 4 936efede29Sratchov #define MIO_IN 8 94fcb16ac0Sratchov 95fcb16ac0Sratchov /* 96fcb16ac0Sratchov * default bytes per sample for the given bits per sample 97fcb16ac0Sratchov */ 98fcb16ac0Sratchov #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) 99fcb16ac0Sratchov 100fcb16ac0Sratchov /* 101fcb16ac0Sratchov * default value of "sio_par->le" flag 102fcb16ac0Sratchov */ 103fcb16ac0Sratchov #if BYTE_ORDER == LITTLE_ENDIAN 104fcb16ac0Sratchov #define SIO_LE_NATIVE 1 105fcb16ac0Sratchov #else 106fcb16ac0Sratchov #define SIO_LE_NATIVE 0 107fcb16ac0Sratchov #endif 108fcb16ac0Sratchov 109fcb16ac0Sratchov /* 110fcb16ac0Sratchov * maximum value of volume, eg. for sio_setvol() 111fcb16ac0Sratchov */ 112fcb16ac0Sratchov #define SIO_MAXVOL 127 113fcb16ac0Sratchov 114fcb16ac0Sratchov #ifdef __cplusplus 115fcb16ac0Sratchov extern "C" { 116fcb16ac0Sratchov #endif 117fcb16ac0Sratchov 118fcb16ac0Sratchov struct pollfd; 119fcb16ac0Sratchov 120fcb16ac0Sratchov void sio_initpar(struct sio_par *); 1217207b069Sratchov struct sio_hdl *sio_open(const char *, unsigned int, int); 122fcb16ac0Sratchov void sio_close(struct sio_hdl *); 123fcb16ac0Sratchov int sio_setpar(struct sio_hdl *, struct sio_par *); 124fcb16ac0Sratchov int sio_getpar(struct sio_hdl *, struct sio_par *); 125fcb16ac0Sratchov int sio_getcap(struct sio_hdl *, struct sio_cap *); 126fcb16ac0Sratchov void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); 127bb957eeeSratchov size_t sio_write(struct sio_hdl *, const void *, size_t); 128fcb16ac0Sratchov size_t sio_read(struct sio_hdl *, void *, size_t); 129fcb16ac0Sratchov int sio_start(struct sio_hdl *); 130fcb16ac0Sratchov int sio_stop(struct sio_hdl *); 131fcb16ac0Sratchov int sio_nfds(struct sio_hdl *); 132fcb16ac0Sratchov int sio_pollfd(struct sio_hdl *, struct pollfd *, int); 133fcb16ac0Sratchov int sio_revents(struct sio_hdl *, struct pollfd *); 134fcb16ac0Sratchov int sio_eof(struct sio_hdl *); 1357207b069Sratchov int sio_setvol(struct sio_hdl *, unsigned int); 1367207b069Sratchov int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *); 137fcb16ac0Sratchov 1387207b069Sratchov struct mio_hdl *mio_open(const char *, unsigned int, int); 1396efede29Sratchov void mio_close(struct mio_hdl *); 140bb957eeeSratchov size_t mio_write(struct mio_hdl *, const void *, size_t); 1416efede29Sratchov size_t mio_read(struct mio_hdl *, void *, size_t); 1426efede29Sratchov int mio_nfds(struct mio_hdl *); 1436efede29Sratchov int mio_pollfd(struct mio_hdl *, struct pollfd *, int); 1446efede29Sratchov int mio_revents(struct mio_hdl *, struct pollfd *); 1456efede29Sratchov int mio_eof(struct mio_hdl *); 1466efede29Sratchov 147fcb16ac0Sratchov #ifdef __cplusplus 148fcb16ac0Sratchov } 149fcb16ac0Sratchov #endif 150fcb16ac0Sratchov 151fcb16ac0Sratchov #endif /* !defined(SNDIO_H) */ 152