[BACK]Return to sndio.h CVS log [TXT][DIR] Up to [local] / src / include

Annotation of src/include/sndio.h, Revision 1.4

1.4     ! ratchov     1: /*     $OpenBSD$       */
1.1       ratchov     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:  */
                     25: struct sio_hdl;
1.2       ratchov    26: struct mio_hdl;
1.1       ratchov    27:
                     28: /*
                     29:  * parameters of a full-duplex stream
                     30:  */
                     31: struct 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:  */
                     54: struct 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
1.2       ratchov    86: #define MIO_OUT                4
                     87: #define MIO_IN         8
1.1       ratchov    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
                    109: extern "C" {
                    110: #endif
                    111:
                    112: struct pollfd;
                    113:
                    114: void sio_initpar(struct sio_par *);
1.3       ratchov   115: struct sio_hdl *sio_open(const char *, unsigned, int);
1.1       ratchov   116: void sio_close(struct sio_hdl *);
                    117: int sio_setpar(struct sio_hdl *, struct sio_par *);
                    118: int sio_getpar(struct sio_hdl *, struct sio_par *);
                    119: int sio_getcap(struct sio_hdl *, struct sio_cap *);
                    120: void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
1.3       ratchov   121: size_t sio_write(struct sio_hdl *, const void *, size_t);
1.1       ratchov   122: size_t sio_read(struct sio_hdl *, void *, size_t);
                    123: int sio_start(struct sio_hdl *);
                    124: int sio_stop(struct sio_hdl *);
                    125: int sio_nfds(struct sio_hdl *);
                    126: int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
                    127: int sio_revents(struct sio_hdl *, struct pollfd *);
                    128: int sio_eof(struct sio_hdl *);
                    129: int sio_setvol(struct sio_hdl *, unsigned);
1.4     ! ratchov   130: int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned), void *);
1.2       ratchov   131:
1.3       ratchov   132: struct mio_hdl *mio_open(const char *, unsigned, int);
1.2       ratchov   133: void mio_close(struct mio_hdl *);
1.3       ratchov   134: size_t mio_write(struct mio_hdl *, const void *, size_t);
1.2       ratchov   135: size_t mio_read(struct mio_hdl *, void *, size_t);
                    136: int mio_nfds(struct mio_hdl *);
                    137: int mio_pollfd(struct mio_hdl *, struct pollfd *, int);
                    138: int mio_revents(struct mio_hdl *, struct pollfd *);
                    139: int mio_eof(struct mio_hdl *);
1.1       ratchov   140:
                    141: #ifdef __cplusplus
                    142: }
                    143: #endif
                    144:
                    145: #endif /* !defined(SNDIO_H) */