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

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

1.11    ! ratchov     1: /*     $OpenBSD: sndio.h,v 1.10 2020/02/26 13:53:58 ratchov Exp $      */
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:
1.7       ratchov    20: #include <sys/types.h>
1.6       ratchov    21:
                     22: /*
                     23:  * default audio device and MIDI port
                     24:  */
                     25: #define SIO_DEVANY     "default"
                     26: #define MIO_PORTANY    "default"
1.1       ratchov    27:
                     28: /*
1.10      ratchov    29:  * limits
                     30:  */
                     31: #define SIOCTL_NAMEMAX         12      /* max name length */
                     32:
                     33: /*
1.1       ratchov    34:  * private ``handle'' structure
                     35:  */
                     36: struct sio_hdl;
1.2       ratchov    37: struct mio_hdl;
1.10      ratchov    38: struct sioctl_hdl;
1.1       ratchov    39:
                     40: /*
                     41:  * parameters of a full-duplex stream
                     42:  */
                     43: struct sio_par {
1.5       ratchov    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 */
1.1       ratchov    53: #define SIO_IGNORE     0       /* pause during xrun */
                     54: #define SIO_SYNC       1       /* resync after xrun */
                     55: #define SIO_ERROR      2       /* terminate on xrun */
1.5       ratchov    56:        unsigned int xrun;      /* what to do on overruns/underruns */
                     57:        unsigned int round;     /* optimal bufsz divisor */
                     58:        unsigned int appbufsz;  /* minimum buffer size */
1.1       ratchov    59:        int __pad[3];           /* for future use */
1.8       espie      60:        unsigned int __magic;   /* for internal/debug purposes only */
1.1       ratchov    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 */
1.5       ratchov    72:                unsigned int bits;
                     73:                unsigned int bps;
                     74:                unsigned int sig;
                     75:                unsigned int le;
                     76:                unsigned int msb;
1.1       ratchov    77:        } enc[SIO_NENC];
1.5       ratchov    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 */
1.1       ratchov    81:        int __pad[7];                   /* for future use */
1.5       ratchov    82:        unsigned int nconf;             /* number of elements in confs[] */
1.1       ratchov    83:        struct sio_conf {
1.5       ratchov    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 */
1.1       ratchov    88:        } confs[SIO_NCONF];
                     89: };
                     90:
                     91: #define SIO_XSTRINGS { "ignore", "sync", "error" }
                     92:
                     93: /*
1.10      ratchov    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 */
1.11    ! ratchov   107: #define SIOCTL_NUM             2       /* integer in the 0..maxval range */
1.10      ratchov   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:        unsigned int type;              /* one of above */
                    112:        char func[SIOCTL_NAMEMAX];      /* function name, ex. "level" */
                    113:        char group[SIOCTL_NAMEMAX];     /* group this control belongs to */
                    114:        struct sioctl_node node0;       /* affected node */
                    115:        struct sioctl_node node1;       /* dito for SIOCTL_{VEC,LIST} */
1.11    ! ratchov   116:        unsigned int maxval;            /* max value */
1.10      ratchov   117:        int __pad[3];
                    118: };
                    119:
                    120: /*
1.1       ratchov   121:  * mode bitmap
                    122:  */
                    123: #define SIO_PLAY       1
                    124: #define SIO_REC                2
1.2       ratchov   125: #define MIO_OUT                4
                    126: #define MIO_IN         8
1.10      ratchov   127: #define SIOCTL_READ    0x100
                    128: #define SIOCTL_WRITE   0x200
1.1       ratchov   129:
                    130: /*
                    131:  * default bytes per sample for the given bits per sample
                    132:  */
                    133: #define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
                    134:
                    135: /*
                    136:  * default value of "sio_par->le" flag
                    137:  */
                    138: #if BYTE_ORDER == LITTLE_ENDIAN
                    139: #define SIO_LE_NATIVE 1
                    140: #else
                    141: #define SIO_LE_NATIVE 0
                    142: #endif
                    143:
                    144: /*
                    145:  * maximum value of volume, eg. for sio_setvol()
                    146:  */
                    147: #define SIO_MAXVOL 127
                    148:
                    149: #ifdef __cplusplus
                    150: extern "C" {
                    151: #endif
                    152:
                    153: struct pollfd;
                    154:
                    155: void sio_initpar(struct sio_par *);
1.5       ratchov   156: struct sio_hdl *sio_open(const char *, unsigned int, int);
1.1       ratchov   157: void sio_close(struct sio_hdl *);
                    158: int sio_setpar(struct sio_hdl *, struct sio_par *);
                    159: int sio_getpar(struct sio_hdl *, struct sio_par *);
                    160: int sio_getcap(struct sio_hdl *, struct sio_cap *);
                    161: void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
1.3       ratchov   162: size_t sio_write(struct sio_hdl *, const void *, size_t);
1.1       ratchov   163: size_t sio_read(struct sio_hdl *, void *, size_t);
                    164: int sio_start(struct sio_hdl *);
                    165: int sio_stop(struct sio_hdl *);
                    166: int sio_nfds(struct sio_hdl *);
                    167: int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
                    168: int sio_revents(struct sio_hdl *, struct pollfd *);
                    169: int sio_eof(struct sio_hdl *);
1.5       ratchov   170: int sio_setvol(struct sio_hdl *, unsigned int);
                    171: int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *);
1.2       ratchov   172:
1.5       ratchov   173: struct mio_hdl *mio_open(const char *, unsigned int, int);
1.2       ratchov   174: void mio_close(struct mio_hdl *);
1.3       ratchov   175: size_t mio_write(struct mio_hdl *, const void *, size_t);
1.2       ratchov   176: size_t mio_read(struct mio_hdl *, void *, size_t);
                    177: int mio_nfds(struct mio_hdl *);
                    178: int mio_pollfd(struct mio_hdl *, struct pollfd *, int);
                    179: int mio_revents(struct mio_hdl *, struct pollfd *);
                    180: int mio_eof(struct mio_hdl *);
1.9       ratchov   181:
1.10      ratchov   182: struct sioctl_hdl *sioctl_open(const char *, unsigned int, int);
                    183: void sioctl_close(struct sioctl_hdl *);
                    184: int sioctl_ondesc(struct sioctl_hdl *,
                    185:     void (*)(void *, struct sioctl_desc *, int), void *);
                    186: int sioctl_onval(struct sioctl_hdl *,
                    187:     void (*)(void *, unsigned int, unsigned int), void *);
                    188: int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int);
                    189: int sioctl_nfds(struct sioctl_hdl *);
                    190: int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int);
                    191: int sioctl_revents(struct sioctl_hdl *, struct pollfd *);
                    192: int sioctl_eof(struct sioctl_hdl *);
                    193:
1.9       ratchov   194: int mio_rmidi_getfd(const char *, unsigned int, int);
                    195: struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int);
                    196: int sio_sun_getfd(const char *, unsigned int, int);
                    197: struct sio_hdl *sio_sun_fdopen(int, unsigned int, int);
1.10      ratchov   198: int sioctl_sun_getfd(const char *, unsigned int, int);
                    199: struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int);
1.1       ratchov   200:
                    201: #ifdef __cplusplus
                    202: }
                    203: #endif
                    204:
                    205: #endif /* !defined(SNDIO_H) */