sndio.h revision 1.4
1/* $OpenBSD: sndio.h,v 1.4 2010/11/06 20:25:42 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/param.h> 21 22/* 23 * private ``handle'' structure 24 */ 25struct sio_hdl; 26struct mio_hdl; 27 28/* 29 * parameters of a full-duplex stream 30 */ 31struct sio_par { 32 unsigned bits; /* bits per sample */ 33 unsigned bps; /* bytes per sample */ 34 unsigned sig; /* 1 = signed, 0 = unsigned */ 35 unsigned le; /* 1 = LE, 0 = BE byte order */ 36 unsigned msb; /* 1 = MSB, 0 = LSB aligned */ 37 unsigned rchan; /* number channels for recording direction */ 38 unsigned pchan; /* number channels for playback direction */ 39 unsigned rate; /* frames per second */ 40 unsigned bufsz; /* end-to-end buffer size */ 41#define SIO_IGNORE 0 /* pause during xrun */ 42#define SIO_SYNC 1 /* resync after xrun */ 43#define SIO_ERROR 2 /* terminate on xrun */ 44 unsigned xrun; /* what to do on overruns/underruns */ 45 unsigned round; /* optimal bufsz divisor */ 46 unsigned appbufsz; /* minimum buffer size */ 47 int __pad[3]; /* for future use */ 48 int __magic; /* for internal/debug purposes only */ 49}; 50 51/* 52 * capabilities of a stream 53 */ 54struct sio_cap { 55#define SIO_NENC 8 56#define SIO_NCHAN 8 57#define SIO_NRATE 16 58#define SIO_NCONF 4 59 struct sio_enc { /* allowed sample encodings */ 60 unsigned bits; 61 unsigned bps; 62 unsigned sig; 63 unsigned le; 64 unsigned msb; 65 } enc[SIO_NENC]; 66 unsigned rchan[SIO_NCHAN]; /* allowed values for rchan */ 67 unsigned pchan[SIO_NCHAN]; /* allowed values for pchan */ 68 unsigned rate[SIO_NRATE]; /* allowed rates */ 69 int __pad[7]; /* for future use */ 70 unsigned nconf; /* number of elements in confs[] */ 71 struct sio_conf { 72 unsigned enc; /* mask of enc[] indexes */ 73 unsigned rchan; /* mask of chan[] indexes (rec) */ 74 unsigned pchan; /* mask of chan[] indexes (play) */ 75 unsigned rate; /* mask of rate[] indexes */ 76 } confs[SIO_NCONF]; 77}; 78 79#define SIO_XSTRINGS { "ignore", "sync", "error" } 80 81/* 82 * mode bitmap 83 */ 84#define SIO_PLAY 1 85#define SIO_REC 2 86#define MIO_OUT 4 87#define MIO_IN 8 88 89/* 90 * default bytes per sample for the given bits per sample 91 */ 92#define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) 93 94/* 95 * default value of "sio_par->le" flag 96 */ 97#if BYTE_ORDER == LITTLE_ENDIAN 98#define SIO_LE_NATIVE 1 99#else 100#define SIO_LE_NATIVE 0 101#endif 102 103/* 104 * maximum value of volume, eg. for sio_setvol() 105 */ 106#define SIO_MAXVOL 127 107 108#ifdef __cplusplus 109extern "C" { 110#endif 111 112struct pollfd; 113 114void sio_initpar(struct sio_par *); 115struct sio_hdl *sio_open(const char *, unsigned, int); 116void sio_close(struct sio_hdl *); 117int sio_setpar(struct sio_hdl *, struct sio_par *); 118int sio_getpar(struct sio_hdl *, struct sio_par *); 119int sio_getcap(struct sio_hdl *, struct sio_cap *); 120void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); 121size_t sio_write(struct sio_hdl *, const void *, size_t); 122size_t sio_read(struct sio_hdl *, void *, size_t); 123int sio_start(struct sio_hdl *); 124int sio_stop(struct sio_hdl *); 125int sio_nfds(struct sio_hdl *); 126int sio_pollfd(struct sio_hdl *, struct pollfd *, int); 127int sio_revents(struct sio_hdl *, struct pollfd *); 128int sio_eof(struct sio_hdl *); 129int sio_setvol(struct sio_hdl *, unsigned); 130int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *); 131 132struct mio_hdl *mio_open(const char *, unsigned, int); 133void mio_close(struct mio_hdl *); 134size_t mio_write(struct mio_hdl *, const void *, size_t); 135size_t mio_read(struct mio_hdl *, void *, size_t); 136int mio_nfds(struct mio_hdl *); 137int mio_pollfd(struct mio_hdl *, struct pollfd *, int); 138int mio_revents(struct mio_hdl *, struct pollfd *); 139int mio_eof(struct mio_hdl *); 140 141#ifdef __cplusplus 142} 143#endif 144 145#endif /* !defined(SNDIO_H) */ 146