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