blob: 480ec3bb0324608be5ad4b9ede8c40d003ee301f [file] [log] [blame]
Greg Ward04613a92002-11-30 22:47:45 +00001/*
2 * ossaudiodev -- Python interface to the OSS (Open Sound System) API.
3 * This is the standard audio API for Linux and some
4 * flavours of BSD [XXX which ones?]; it is also available
5 * for a wide range of commercial Unices.
6 *
7 * Originally written by Peter Bosch, March 2000, as linuxaudiodev.
8 *
9 * Renamed to ossaudiodev and rearranged/revised/hacked up
10 * by Greg Ward <gward@python.net>, November 2002.
Greg Ward3d9994d2002-12-11 15:12:01 +000011 * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002.
Greg Ward04613a92002-11-30 22:47:45 +000012 *
13 * (c) 2000 Peter Bosch. All Rights Reserved.
14 * (c) 2002 Gregory P. Ward. All Rights Reserved.
15 * (c) 2002 Python Software Foundation. All Rights Reserved.
16 *
17 * XXX need a license statement
18 *
19 * $Id$
20 */
21
22#include "Python.h"
23#include "structmember.h"
24
25#ifdef HAVE_FCNTL_H
26#include <fcntl.h>
27#else
28#define O_RDONLY 00
29#define O_WRONLY 01
30#endif
31
32
33#include <sys/ioctl.h>
34#if defined(linux)
35#include <linux/soundcard.h>
36
37typedef unsigned long uint32_t;
38
39#elif defined(__FreeBSD__)
40#include <machine/soundcard.h>
41
42#ifndef SNDCTL_DSP_CHANNELS
43#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
44#endif
45
46#endif
47
48typedef struct {
49 PyObject_HEAD;
Greg Ward7b43c682002-12-30 02:29:28 +000050 int fd; /* The open file */
51 int mode; /* file mode */
52 int icount; /* Input count */
53 int ocount; /* Output count */
54 uint32_t afmts; /* Audio formats supported by hardware */
Greg Ward8c6b6a92002-12-11 14:43:13 +000055} oss_t;
Greg Ward04613a92002-11-30 22:47:45 +000056
Greg Ward3d9994d2002-12-11 15:12:01 +000057typedef struct {
58 PyObject_HEAD;
Greg Ward7b43c682002-12-30 02:29:28 +000059 int fd; /* The open mixer device */
Greg Ward3d9994d2002-12-11 15:12:01 +000060} oss_mixer_t;
61
Greg Ward04613a92002-11-30 22:47:45 +000062/* XXX several format defined in soundcard.h are not supported,
63 including _NE (native endian) options and S32 options
64*/
65
66static struct {
67 int a_bps;
68 uint32_t a_fmt;
69 char *a_name;
70} audio_types[] = {
71 { 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" },
72 { 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" },
73 { 8, AFMT_U8, "linear unsigned 8-bit audio" },
74 { 8, AFMT_S8, "linear signed 8-bit audio" },
75 { 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" },
76 { 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" },
77 { 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" },
78 { 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" },
79 { 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" },
80};
81
82static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]);
83
Greg Ward8c6b6a92002-12-11 14:43:13 +000084static PyTypeObject OSSType;
Greg Ward3d9994d2002-12-11 15:12:01 +000085static PyTypeObject OSSMixerType;
Greg Ward04613a92002-11-30 22:47:45 +000086
Greg Ward97708bc2002-11-30 23:17:10 +000087static PyObject *OSSAudioError;
Greg Ward04613a92002-11-30 22:47:45 +000088
Greg Ward8c6b6a92002-12-11 14:43:13 +000089static oss_t *
90newossobject(PyObject *arg)
Greg Ward04613a92002-11-30 22:47:45 +000091{
Greg Ward8c6b6a92002-12-11 14:43:13 +000092 oss_t *xp;
Greg Ward04613a92002-11-30 22:47:45 +000093 int fd, afmts, imode;
94 char *basedev = NULL;
95 char *mode = NULL;
96
Greg Ward9a568eb2002-11-30 23:20:09 +000097 /* Two ways to call open():
Greg Ward04613a92002-11-30 22:47:45 +000098 open(device, mode) (for consistency with builtin open())
99 open(mode) (for backwards compatibility)
100 because the *first* argument is optional, parsing args is
101 a wee bit tricky. */
102 if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode))
103 return NULL;
104 if (mode == NULL) { /* only one arg supplied */
105 mode = basedev;
106 basedev = NULL;
107 }
108
109 if (strcmp(mode, "r") == 0)
110 imode = O_RDONLY;
111 else if (strcmp(mode, "w") == 0)
112 imode = O_WRONLY;
Greg Ward1e0f57d2002-11-30 23:05:26 +0000113 else if (strcmp(mode, "rw") == 0)
114 imode = O_RDWR;
Greg Ward04613a92002-11-30 22:47:45 +0000115 else {
Greg Ward97708bc2002-11-30 23:17:10 +0000116 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
Greg Ward04613a92002-11-30 22:47:45 +0000117 return NULL;
118 }
119
120 /* Open the correct device. The base device name comes from the
121 * AUDIODEV environment variable first, then /dev/dsp. The
122 * control device tacks "ctl" onto the base device name.
123 *
124 * Note that the only difference between /dev/audio and /dev/dsp
125 * is that the former uses logarithmic mu-law encoding and the
126 * latter uses 8-bit unsigned encoding.
127 */
128
129 if (basedev == NULL) { /* called with one arg */
130 basedev = getenv("AUDIODEV");
131 if (basedev == NULL) /* $AUDIODEV not set */
132 basedev = "/dev/dsp";
133 }
134
135 if ((fd = open(basedev, imode)) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000136 PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
Greg Ward04613a92002-11-30 22:47:45 +0000137 return NULL;
138 }
Greg Ward04613a92002-11-30 22:47:45 +0000139 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000140 PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
Greg Ward04613a92002-11-30 22:47:45 +0000141 return NULL;
142 }
143 /* Create and initialize the object */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000144 if ((xp = PyObject_New(oss_t, &OSSType)) == NULL) {
Greg Ward04613a92002-11-30 22:47:45 +0000145 close(fd);
146 return NULL;
147 }
Greg Ward7b43c682002-12-30 02:29:28 +0000148 xp->fd = fd;
149 xp->mode = imode;
150 xp->icount = xp->ocount = 0;
151 xp->afmts = afmts;
Greg Ward04613a92002-11-30 22:47:45 +0000152 return xp;
153}
154
155static void
Greg Ward8c6b6a92002-12-11 14:43:13 +0000156oss_dealloc(oss_t *xp)
Greg Ward04613a92002-11-30 22:47:45 +0000157{
158 /* if already closed, don't reclose it */
Greg Ward7b43c682002-12-30 02:29:28 +0000159 if (xp->fd != -1)
160 close(xp->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000161 PyObject_Del(xp);
162}
163
Greg Ward3d9994d2002-12-11 15:12:01 +0000164static oss_mixer_t *
165newossmixerobject(PyObject *arg)
166{
167 char *basedev = NULL, *mode = NULL;
168 int fd, imode;
169 oss_mixer_t *xp;
170
171 if (!PyArg_ParseTuple (arg, "|ss", &basedev, &mode)) {
172 return NULL;
173 }
174
175 if (basedev == NULL) {
176 basedev = getenv("MIXERDEV");
177 if (basedev == NULL) /* MIXERDEV not set */
178 basedev = "/dev/mixer";
179 }
180
181 if (mode == NULL || strcmp(mode, "r") == 0)
182 imode = O_RDONLY;
183 else if (strcmp(mode, "w") == 0)
184 imode = O_WRONLY;
185 else if (strcmp(mode, "rw") == 0)
186 imode = O_RDWR;
187 else {
188 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
189 return NULL;
190 }
191
192 if ((fd = open (basedev, imode)) == -1) {
193 PyErr_SetFromErrnoWithFilename(PyExc_IOError, basedev);
194 return NULL;
195 }
196
197 if ((xp = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
198 close(fd);
199 return NULL;
200 }
201
Greg Ward7b43c682002-12-30 02:29:28 +0000202 xp->fd = fd;
Greg Ward3d9994d2002-12-11 15:12:01 +0000203
204 return xp;
205}
206
207static void
208oss_mixer_dealloc(oss_mixer_t *xp)
209{
210 /* if already closed, don't reclose it */
Greg Ward7b43c682002-12-30 02:29:28 +0000211 if (xp->fd != -1)
212 close(xp->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000213 PyObject_Del(xp);
214}
215
Greg Ward131bce02002-11-30 22:56:44 +0000216
217/* Methods to wrap the OSS ioctls. The calling convention is pretty
218 simple:
219 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
220 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
221 etc.
222*/
223
224
225/* _do_ioctl_1() is a private helper function used for the OSS ioctls --
226 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C
227 like this:
228 ioctl(fd, SNDCTL_DSP_cmd, &arg)
229
230 where arg is the value to set, and on return the driver sets arg to
231 the value that was actually set. Mapping this to Python is obvious:
232 arg = dsp.xxx(arg)
233*/
234static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000235_do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000236{
Greg Wardda9f8532002-12-11 14:49:59 +0000237 char argfmt[33] = "i:";
Greg Ward131bce02002-11-30 22:56:44 +0000238 int arg;
239
Greg Wardda9f8532002-12-11 14:49:59 +0000240 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000241 strcat(argfmt, fname);
242 if (!PyArg_ParseTuple(args, argfmt, &arg))
243 return NULL;
244
Greg Wardda9f8532002-12-11 14:49:59 +0000245 if (ioctl(fd, cmd, &arg) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000246 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000247 return PyInt_FromLong(arg);
248}
249
Greg Ward3d9994d2002-12-11 15:12:01 +0000250/* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
251 but return an output -- ie. we need to pass a pointer to a local C
252 variable so the driver can write its output there, but from Python
253 all we see is the return value. For example,
254 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
255 devices, but does not use the value of the parameter passed-in in any
256 way.
257*/
258
259static PyObject *
260_do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
261{
262 char argfmt[32] = ":";
263 int arg = 0;
264
265 assert(strlen(fname) <= 30);
266 strcat(argfmt, fname);
267 if (!PyArg_ParseTuple(args, argfmt, &arg))
268 return NULL;
269
270 if (ioctl(fd, cmd, &arg) == -1)
271 return PyErr_SetFromErrno(PyExc_IOError);
272 return PyInt_FromLong(arg);
273}
274
275
276
Greg Ward131bce02002-11-30 22:56:44 +0000277/* _do_ioctl_0() is a private helper for the no-argument ioctls:
278 SNDCTL_DSP_{SYNC,RESET,POST}. */
279static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000280_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000281{
Greg Wardda9f8532002-12-11 14:49:59 +0000282 char argfmt[32] = ":";
Greg Ward131bce02002-11-30 22:56:44 +0000283
Greg Wardda9f8532002-12-11 14:49:59 +0000284 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000285 strcat(argfmt, fname);
286 if (!PyArg_ParseTuple(args, argfmt))
287 return NULL;
288
Greg Wardda9f8532002-12-11 14:49:59 +0000289 if (ioctl(fd, cmd, 0) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000290 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000291 Py_INCREF(Py_None);
292 return Py_None;
293}
294
295
296static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000297oss_nonblock(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000298{
299 /* Hmmm: it doesn't appear to be possible to return to blocking
300 mode once we're in non-blocking mode! */
301 if (!PyArg_ParseTuple(args, ":nonblock"))
302 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000303 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000304 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000305 Py_INCREF(Py_None);
306 return Py_None;
307}
308
309static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000310oss_setfmt(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000311{
Greg Ward7b43c682002-12-30 02:29:28 +0000312 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
Greg Ward131bce02002-11-30 22:56:44 +0000313}
314
315static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000316oss_getfmts(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000317{
318 int mask;
319 if (!PyArg_ParseTuple(args, ":getfmts"))
320 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000321 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000322 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000323 return PyInt_FromLong(mask);
324}
325
326static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000327oss_channels(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000328{
Greg Ward7b43c682002-12-30 02:29:28 +0000329 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
Greg Ward131bce02002-11-30 22:56:44 +0000330}
331
332static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000333oss_speed(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000334{
Greg Ward7b43c682002-12-30 02:29:28 +0000335 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
Greg Ward131bce02002-11-30 22:56:44 +0000336}
337
338static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000339oss_sync(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000340{
Greg Ward7b43c682002-12-30 02:29:28 +0000341 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000342}
343
344static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000345oss_reset(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000346{
Greg Ward7b43c682002-12-30 02:29:28 +0000347 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
Greg Ward131bce02002-11-30 22:56:44 +0000348}
349
350static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000351oss_post(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000352{
Greg Ward7b43c682002-12-30 02:29:28 +0000353 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
Greg Ward131bce02002-11-30 22:56:44 +0000354}
355
356
357/* Regular file methods: read(), write(), close(), etc. as well
358 as one convenience method, writeall(). */
359
Greg Ward04613a92002-11-30 22:47:45 +0000360static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000361oss_read(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000362{
363 int size, count;
364 char *cp;
365 PyObject *rv;
366
367 if (!PyArg_ParseTuple(args, "i:read", &size))
368 return NULL;
369 rv = PyString_FromStringAndSize(NULL, size);
370 if (rv == NULL)
371 return NULL;
372 cp = PyString_AS_STRING(rv);
Greg Ward7b43c682002-12-30 02:29:28 +0000373 if ((count = read(self->fd, cp, size)) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000374 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000375 Py_DECREF(rv);
376 return NULL;
377 }
Greg Ward7b43c682002-12-30 02:29:28 +0000378 self->icount += count;
Greg Ward04613a92002-11-30 22:47:45 +0000379 _PyString_Resize(&rv, count);
380 return rv;
381}
382
383static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000384oss_write(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000385{
386 char *cp;
387 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000388
389 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
Greg Ward04613a92002-11-30 22:47:45 +0000390 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000391 }
Greg Ward7b43c682002-12-30 02:29:28 +0000392 if ((rv = write(self->fd, cp, size)) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000393 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000394 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000395 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000396 }
397 return PyInt_FromLong(rv);
398}
399
400static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000401oss_writeall(oss_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000402{
403 char *cp;
404 int rv, size;
405 fd_set write_set_fds;
406 int select_rv;
407
408 /* NB. writeall() is only useful in non-blocking mode: according to
409 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
410 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
411 write() in blocking mode consumes the whole buffer. In blocking
412 mode, the behaviour of write() and writeall() from Python is
413 indistinguishable. */
414
415 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
416 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000417
418 /* use select to wait for audio device to be available */
419 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000420 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000421
422 while (size > 0) {
Greg Ward7b43c682002-12-30 02:29:28 +0000423 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward131bce02002-11-30 22:56:44 +0000424 assert(select_rv != 0); /* no timeout, can't expire */
425 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000426 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000427
Greg Ward7b43c682002-12-30 02:29:28 +0000428 rv = write(self->fd, cp, size);
Greg Ward131bce02002-11-30 22:56:44 +0000429 if (rv == -1) {
430 if (errno == EAGAIN) { /* buffer is full, try again */
431 errno = 0;
432 continue;
433 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000434 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000435 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000436 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000437 size -= rv;
438 cp += rv;
439 }
Greg Ward04613a92002-11-30 22:47:45 +0000440 }
441 Py_INCREF(Py_None);
442 return Py_None;
443}
444
445static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000446oss_close(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000447{
448 if (!PyArg_ParseTuple(args, ":close"))
449 return NULL;
450
Greg Ward7b43c682002-12-30 02:29:28 +0000451 if (self->fd >= 0) {
452 close(self->fd);
453 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000454 }
455 Py_INCREF(Py_None);
456 return Py_None;
457}
458
459static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000460oss_fileno(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000461{
462 if (!PyArg_ParseTuple(args, ":fileno"))
463 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000464 return PyInt_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000465}
466
Greg Ward131bce02002-11-30 22:56:44 +0000467
468/* Convenience methods: these generally wrap a couple of ioctls into one
469 common task. */
470
Greg Ward04613a92002-11-30 22:47:45 +0000471static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000472oss_setparameters(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000473{
474 int rate, ssize, nchannels, n, fmt, emulate=0;
475
476 if (!PyArg_ParseTuple(args, "iiii|i:setparameters",
477 &rate, &ssize, &nchannels, &fmt, &emulate))
478 return NULL;
479
480 if (rate < 0) {
481 PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
482 rate);
483 return NULL;
484 }
485 if (ssize < 0) {
486 PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
487 ssize);
488 return NULL;
489 }
490 if (nchannels != 1 && nchannels != 2) {
491 PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
492 nchannels);
493 return NULL;
494 }
495
496 for (n = 0; n < n_audio_types; n++)
497 if (fmt == audio_types[n].a_fmt)
498 break;
499 if (n == n_audio_types) {
500 PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
501 return NULL;
502 }
503 if (audio_types[n].a_bps != ssize) {
504 PyErr_Format(PyExc_ValueError,
505 "for %s, expected sample size %d, not %d",
506 audio_types[n].a_name, audio_types[n].a_bps, ssize);
507 return NULL;
508 }
509
510 if (emulate == 0) {
Greg Ward7b43c682002-12-30 02:29:28 +0000511 if ((self->afmts & audio_types[n].a_fmt) == 0) {
Greg Ward04613a92002-11-30 22:47:45 +0000512 PyErr_Format(PyExc_ValueError,
513 "%s format not supported by device",
514 audio_types[n].a_name);
515 return NULL;
516 }
517 }
Greg Ward7b43c682002-12-30 02:29:28 +0000518 if (ioctl(self->fd, SNDCTL_DSP_SETFMT,
Greg Ward04613a92002-11-30 22:47:45 +0000519 &audio_types[n].a_fmt) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000520 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000521 return NULL;
522 }
Greg Ward7b43c682002-12-30 02:29:28 +0000523 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000524 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000525 return NULL;
526 }
Greg Ward7b43c682002-12-30 02:29:28 +0000527 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000528 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000529 return NULL;
530 }
531
532 Py_INCREF(Py_None);
533 return Py_None;
534}
535
536static int
Greg Ward8c6b6a92002-12-11 14:43:13 +0000537_ssize(oss_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000538{
539 int fmt;
540
541 fmt = 0;
Greg Ward7b43c682002-12-30 02:29:28 +0000542 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000543 return -errno;
544
545 switch (fmt) {
546 case AFMT_MU_LAW:
547 case AFMT_A_LAW:
548 case AFMT_U8:
549 case AFMT_S8:
550 *ssize = sizeof(char);
551 break;
552 case AFMT_S16_LE:
553 case AFMT_S16_BE:
554 case AFMT_U16_LE:
555 case AFMT_U16_BE:
556 *ssize = sizeof(short);
557 break;
558 case AFMT_MPEG:
559 case AFMT_IMA_ADPCM:
560 default:
561 return -EOPNOTSUPP;
562 }
563 *nchannels = 0;
Greg Ward7b43c682002-12-30 02:29:28 +0000564 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000565 return -errno;
566 return 0;
567}
568
569
570/* bufsize returns the size of the hardware audio buffer in number
571 of samples */
572static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000573oss_bufsize(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000574{
575 audio_buf_info ai;
576 int nchannels, ssize;
577
578 if (!PyArg_ParseTuple(args, ":bufsize")) return NULL;
579
580 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000581 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000582 return NULL;
583 }
Greg Ward7b43c682002-12-30 02:29:28 +0000584 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000585 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000586 return NULL;
587 }
588 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
589}
590
591/* obufcount returns the number of samples that are available in the
592 hardware for playing */
593static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000594oss_obufcount(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000595{
596 audio_buf_info ai;
597 int nchannels, ssize;
598
599 if (!PyArg_ParseTuple(args, ":obufcount"))
600 return NULL;
601
602 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000603 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000604 return NULL;
605 }
Greg Ward7b43c682002-12-30 02:29:28 +0000606 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000607 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000608 return NULL;
609 }
610 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
611 (ssize * nchannels));
612}
613
614/* obufcount returns the number of samples that can be played without
615 blocking */
616static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000617oss_obuffree(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000618{
619 audio_buf_info ai;
620 int nchannels, ssize;
621
622 if (!PyArg_ParseTuple(args, ":obuffree"))
623 return NULL;
624
625 if (_ssize(self, &nchannels, &ssize) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000626 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000627 return NULL;
628 }
Greg Ward7b43c682002-12-30 02:29:28 +0000629 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000630 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000631 return NULL;
632 }
633 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
634}
635
Greg Ward04613a92002-11-30 22:47:45 +0000636static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000637oss_getptr(oss_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000638{
639 count_info info;
640 int req;
641
642 if (!PyArg_ParseTuple(args, ":getptr"))
643 return NULL;
644
Greg Ward7b43c682002-12-30 02:29:28 +0000645 if (self->mode == O_RDONLY)
Greg Ward04613a92002-11-30 22:47:45 +0000646 req = SNDCTL_DSP_GETIPTR;
647 else
648 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000649 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000650 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000651 return NULL;
652 }
653 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
654}
655
Greg Ward3d9994d2002-12-11 15:12:01 +0000656/* Mixer methods */
657static PyObject *
658oss_mixer_close(oss_mixer_t *self, PyObject *args)
659{
660 if (!PyArg_ParseTuple(args, ":close"))
661 return NULL;
662
Greg Ward7b43c682002-12-30 02:29:28 +0000663 if (self->fd >= 0) {
664 close(self->fd);
665 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000666 }
667 Py_INCREF(Py_None);
668 return Py_None;
669}
670
671static PyObject *
672oss_mixer_fileno(oss_mixer_t *self, PyObject *args)
673{
674 if (!PyArg_ParseTuple(args, ":fileno"))
675 return NULL;
Greg Ward7b43c682002-12-30 02:29:28 +0000676 return PyInt_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000677}
678
679/* Simple mixer interface methods */
680
681static PyObject *
682oss_mixer_channels (oss_mixer_t *self, PyObject *args)
683{
Greg Ward7b43c682002-12-30 02:29:28 +0000684 return _do_ioctl_1_internal(self->fd, args, "channels",
Greg Ward3d9994d2002-12-11 15:12:01 +0000685 SOUND_MIXER_READ_DEVMASK);
686}
687
688static PyObject *
689oss_mixer_stereo_channels (oss_mixer_t *self, PyObject *args)
690{
Greg Ward7b43c682002-12-30 02:29:28 +0000691 return _do_ioctl_1_internal(self->fd, args, "stereochannels",
Greg Ward3d9994d2002-12-11 15:12:01 +0000692 SOUND_MIXER_READ_STEREODEVS);
693}
694
695static PyObject *
696oss_mixer_rec_channels (oss_mixer_t *self, PyObject *args)
697{
Greg Ward7b43c682002-12-30 02:29:28 +0000698 return _do_ioctl_1_internal(self->fd, args, "recchannels",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000699 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000700}
701
702static PyObject *
703oss_mixer_getvol (oss_mixer_t *self, PyObject *args)
704{
705 int channel, volume;
706
707 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
708 if (!PyArg_ParseTuple (args, "i:getvol", &channel))
709 return NULL;
710
711 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
712 PyErr_SetString (OSSAudioError, "Invalid mixer channel specified.");
713 return NULL;
714 }
715
Greg Ward7b43c682002-12-30 02:29:28 +0000716 if (ioctl (self->fd, MIXER_READ(channel), &volume) == -1)
Greg Ward3d9994d2002-12-11 15:12:01 +0000717 return PyErr_SetFromErrno(PyExc_IOError);
718
719 return Py_BuildValue ("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
720}
721
722static PyObject *
723oss_mixer_setvol (oss_mixer_t *self, PyObject *args)
724{
725 int channel, volume, leftVol, rightVol;
726
727 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
728 if (!PyArg_ParseTuple (args, "i(ii):setvol", &channel, &leftVol, &rightVol))
729 return NULL;
730
731 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
732 PyErr_SetString (OSSAudioError, "Invalid mixer channel specified.");
733 return NULL;
734 }
735
736 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
737 PyErr_SetString (OSSAudioError, "Volumes must be between 0 and 100.");
738 return NULL;
739 }
740
741 volume = (rightVol << 8) | leftVol;
742
Greg Ward7b43c682002-12-30 02:29:28 +0000743 if (ioctl (self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Ward3d9994d2002-12-11 15:12:01 +0000744 return PyErr_SetFromErrno(PyExc_IOError);
745
746 return Py_BuildValue ("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
747}
748
749static PyObject *
750oss_mixer_getrecsrc (oss_mixer_t *self, PyObject *args)
751{
Greg Ward7b43c682002-12-30 02:29:28 +0000752 return _do_ioctl_1_internal(self->fd, args, "getrecsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000753 SOUND_MIXER_READ_RECSRC);
754}
755
756static PyObject *
757oss_mixer_setrecsrc (oss_mixer_t *self, PyObject *args)
758{
Greg Ward7b43c682002-12-30 02:29:28 +0000759 return _do_ioctl_1(self->fd, args, "setrecsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000760 SOUND_MIXER_WRITE_RECSRC);
761}
762
763
Greg Ward8c6b6a92002-12-11 14:43:13 +0000764static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000765 /* Regular file methods */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000766 { "read", (PyCFunction)oss_read, METH_VARARGS },
767 { "write", (PyCFunction)oss_write, METH_VARARGS },
768 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
769 { "close", (PyCFunction)oss_close, METH_VARARGS },
770 { "fileno", (PyCFunction)oss_fileno, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000771
772 /* Simple ioctl wrappers */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000773 { "nonblock", (PyCFunction)oss_nonblock, METH_VARARGS },
774 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
775 { "getfmts", (PyCFunction)oss_getfmts, METH_VARARGS },
776 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
777 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
778 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
779 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
780 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000781
782 /* Convenience methods -- wrap a couple of ioctls together */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000783 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
784 { "bufsize", (PyCFunction)oss_bufsize, METH_VARARGS },
785 { "obufcount", (PyCFunction)oss_obufcount, METH_VARARGS },
786 { "obuffree", (PyCFunction)oss_obuffree, METH_VARARGS },
787 { "getptr", (PyCFunction)oss_getptr, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000788
789 /* Aliases for backwards compatibility */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000790 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000791
Greg Ward04613a92002-11-30 22:47:45 +0000792 { NULL, NULL} /* sentinel */
793};
794
Greg Ward3d9994d2002-12-11 15:12:01 +0000795static PyMethodDef oss_mixer_methods[] = {
796 /* Regular file method - OSS mixers are ioctl-only interface */
797 { "close", (PyCFunction)oss_mixer_close, METH_VARARGS },
798 { "fileno", (PyCFunction)oss_mixer_fileno, METH_VARARGS },
799
800 /* Simple ioctl wrappers */
801 { "channels", (PyCFunction)oss_mixer_channels, METH_VARARGS },
802 { "stereochannels", (PyCFunction)oss_mixer_stereo_channels, METH_VARARGS},
803 { "recchannels", (PyCFunction)oss_mixer_rec_channels, METH_VARARGS},
804 { "getvol", (PyCFunction)oss_mixer_getvol, METH_VARARGS },
805 { "setvol", (PyCFunction)oss_mixer_setvol, METH_VARARGS },
806 { "getrecsrc", (PyCFunction)oss_mixer_getrecsrc, METH_VARARGS },
807 { "setrecsrc", (PyCFunction)oss_mixer_setrecsrc, METH_VARARGS },
808
809 { NULL, NULL}
810};
811
Greg Ward04613a92002-11-30 22:47:45 +0000812static PyObject *
Greg Ward8c6b6a92002-12-11 14:43:13 +0000813oss_getattr(oss_t *xp, char *name)
Greg Ward04613a92002-11-30 22:47:45 +0000814{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000815 return Py_FindMethod(oss_methods, (PyObject *)xp, name);
Greg Ward04613a92002-11-30 22:47:45 +0000816}
817
Greg Ward3d9994d2002-12-11 15:12:01 +0000818static PyObject *
819oss_mixer_getattr(oss_mixer_t *xp, char *name)
820{
821 return Py_FindMethod(oss_mixer_methods, (PyObject *)xp, name);
822}
823
Greg Ward8c6b6a92002-12-11 14:43:13 +0000824static PyTypeObject OSSType = {
Greg Ward04613a92002-11-30 22:47:45 +0000825 PyObject_HEAD_INIT(&PyType_Type)
826 0, /*ob_size*/
Greg Ward9a568eb2002-11-30 23:20:09 +0000827 "ossaudiodev.oss_audio_device", /*tp_name*/
Greg Ward8c6b6a92002-12-11 14:43:13 +0000828 sizeof(oss_t), /*tp_size*/
Greg Ward04613a92002-11-30 22:47:45 +0000829 0, /*tp_itemsize*/
830 /* methods */
Greg Ward8c6b6a92002-12-11 14:43:13 +0000831 (destructor)oss_dealloc, /*tp_dealloc*/
Greg Ward04613a92002-11-30 22:47:45 +0000832 0, /*tp_print*/
Greg Ward8c6b6a92002-12-11 14:43:13 +0000833 (getattrfunc)oss_getattr, /*tp_getattr*/
Greg Ward04613a92002-11-30 22:47:45 +0000834 0, /*tp_setattr*/
835 0, /*tp_compare*/
836 0, /*tp_repr*/
837};
838
Greg Ward3d9994d2002-12-11 15:12:01 +0000839static PyTypeObject OSSMixerType = {
840 PyObject_HEAD_INIT(&PyType_Type)
841 0, /*ob_size*/
842 "ossaudiodev.oss_mixer_device", /*tp_name*/
843 sizeof(oss_mixer_t), /*tp_size*/
844 0, /*tp_itemsize*/
845 /* methods */
846 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
847 0, /*tp_print*/
848 (getattrfunc)oss_mixer_getattr, /*tp_getattr*/
849 0, /*tp_setattr*/
850 0, /*tp_compare*/
851 0, /*tp_repr*/
852};
853
854
Greg Ward04613a92002-11-30 22:47:45 +0000855static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000856ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000857{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000858 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000859}
860
Greg Ward3d9994d2002-12-11 15:12:01 +0000861static PyObject *
862ossopenmixer(PyObject *self, PyObject *args)
863{
864 return (PyObject *)newossmixerobject(args);
865}
866
Greg Ward9a568eb2002-11-30 23:20:09 +0000867static PyMethodDef ossaudiodev_methods[] = {
868 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000869 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000870 { 0, 0 },
871};
872
Greg Ward1e0f57d2002-11-30 23:05:26 +0000873
874#define _EXPORT_INT(mod, name) \
875 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
876
Greg Ward04613a92002-11-30 22:47:45 +0000877void
Greg Ward9a568eb2002-11-30 23:20:09 +0000878initossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000879{
880 PyObject *m;
881
Greg Ward9a568eb2002-11-30 23:20:09 +0000882 m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
Greg Ward04613a92002-11-30 22:47:45 +0000883
Greg Ward97708bc2002-11-30 23:17:10 +0000884 OSSAudioError = PyErr_NewException("ossaudiodev.error", NULL, NULL);
885 if (OSSAudioError)
886 PyModule_AddObject(m, "error", OSSAudioError);
Greg Ward04613a92002-11-30 22:47:45 +0000887
Greg Ward1e0f57d2002-11-30 23:05:26 +0000888 /* Expose the audio format numbers -- essential! */
889 _EXPORT_INT(m, AFMT_QUERY);
890 _EXPORT_INT(m, AFMT_MU_LAW);
891 _EXPORT_INT(m, AFMT_A_LAW);
892 _EXPORT_INT(m, AFMT_IMA_ADPCM);
893 _EXPORT_INT(m, AFMT_U8);
894 _EXPORT_INT(m, AFMT_S16_LE);
895 _EXPORT_INT(m, AFMT_S16_BE);
896 _EXPORT_INT(m, AFMT_S8);
897 _EXPORT_INT(m, AFMT_U16_LE);
898 _EXPORT_INT(m, AFMT_U16_BE);
899 _EXPORT_INT(m, AFMT_MPEG);
900 _EXPORT_INT(m, AFMT_AC3);
901 _EXPORT_INT(m, AFMT_S16_NE);
Greg Ward3d9994d2002-12-11 15:12:01 +0000902
903 /* Expose the sound mixer channels. */
Greg Ward7b43c682002-12-30 02:29:28 +0000904 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +0000905 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
906 _EXPORT_INT(m, SOUND_MIXER_BASS);
907 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
908 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
909 _EXPORT_INT(m, SOUND_MIXER_PCM);
910 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
911 _EXPORT_INT(m, SOUND_MIXER_LINE);
912 _EXPORT_INT(m, SOUND_MIXER_MIC);
913 _EXPORT_INT(m, SOUND_MIXER_CD);
914 _EXPORT_INT(m, SOUND_MIXER_IMIX);
915 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
916 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
917 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
918 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
919 _EXPORT_INT(m, SOUND_MIXER_LINE1);
920 _EXPORT_INT(m, SOUND_MIXER_LINE2);
921 _EXPORT_INT(m, SOUND_MIXER_LINE3);
922 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
923 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
924 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
925 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
926 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
927 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
928 _EXPORT_INT(m, SOUND_MIXER_RADIO);
929 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Ward04613a92002-11-30 22:47:45 +0000930
Greg Ward1e0f57d2002-11-30 23:05:26 +0000931 /* Expose all the ioctl numbers for masochists who like to do this
932 stuff directly. */
933 _EXPORT_INT(m, SNDCTL_COPR_HALT);
934 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
935 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
936 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
937 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
938 _EXPORT_INT(m, SNDCTL_COPR_RESET);
939 _EXPORT_INT(m, SNDCTL_COPR_RUN);
940 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
941 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
942 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
943 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
944 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
945 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
946 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
947 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
948 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
949 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
950 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
951 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
952 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
953 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
954 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
955 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
956 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
957 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
958 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
959 _EXPORT_INT(m, SNDCTL_DSP_POST);
960 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
961 _EXPORT_INT(m, SNDCTL_DSP_RESET);
962 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
963 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
964 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
965 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
966 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
967 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
968 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
969 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
970 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
971 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
972 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
973 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
974 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
975 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
976 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
977 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
978 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
979 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
980 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
981 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
982 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
983 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
984 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
985 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
986 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
987 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
988 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
989 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
990 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
991 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
992 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
993 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
994 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
995 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
996 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
997 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
998 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
999 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1000 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1001 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1002 _EXPORT_INT(m, SNDCTL_TMR_START);
1003 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1004 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1005 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Greg Ward04613a92002-11-30 22:47:45 +00001006}