blob: b3dfa6256314babb33a9accb27662af7529429e8 [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.
Guido van Rossum0741f802003-06-02 14:15:34 +000012 *
Greg Ward04613a92002-11-30 22:47:45 +000013 * (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
Greg Ward04613a92002-11-30 22:47:45 +000032#include <sys/ioctl.h>
Greg Ward0b6dfb82003-03-10 03:17:06 +000033#include <sys/soundcard.h>
34
Greg Ward04613a92002-11-30 22:47:45 +000035#if defined(linux)
Greg Ward04613a92002-11-30 22:47:45 +000036
Armin Rigo0d2f4982006-10-04 10:23:57 +000037#ifndef HAVE_STDINT_H
Greg Ward04613a92002-11-30 22:47:45 +000038typedef unsigned long uint32_t;
Armin Rigo0d2f4982006-10-04 10:23:57 +000039#endif
Greg Ward04613a92002-11-30 22:47:45 +000040
41#elif defined(__FreeBSD__)
Greg Ward04613a92002-11-30 22:47:45 +000042
Greg Ward0b6dfb82003-03-10 03:17:06 +000043# ifndef SNDCTL_DSP_CHANNELS
44# define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
45# endif
Greg Ward04613a92002-11-30 22:47:45 +000046
47#endif
48
49typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000050 PyObject_HEAD
Greg Ward50682d02005-03-07 01:41:11 +000051 char *devicename; /* name of the device file */
52 int fd; /* file descriptor */
53 int mode; /* file mode (O_RDONLY, etc.) */
54 int icount; /* input count */
55 int ocount; /* output count */
56 uint32_t afmts; /* audio formats supported by hardware */
Greg Ward499b73e2002-12-31 03:04:52 +000057} oss_audio_t;
Greg Ward04613a92002-11-30 22:47:45 +000058
Greg Ward3d9994d2002-12-11 15:12:01 +000059typedef struct {
Neal Norwitz3f046482006-01-07 21:19:49 +000060 PyObject_HEAD
Greg Wardad4d9b92002-12-30 03:02:22 +000061 int fd; /* The open mixer device */
Greg Ward3d9994d2002-12-11 15:12:01 +000062} oss_mixer_t;
63
Greg Ward04613a92002-11-30 22:47:45 +000064
Greg Ward499b73e2002-12-31 03:04:52 +000065static PyTypeObject OSSAudioType;
Greg Ward3d9994d2002-12-11 15:12:01 +000066static PyTypeObject OSSMixerType;
Greg Ward04613a92002-11-30 22:47:45 +000067
Greg Ward97708bc2002-11-30 23:17:10 +000068static PyObject *OSSAudioError;
Greg Ward04613a92002-11-30 22:47:45 +000069
Greg Wardda1cacb2002-12-31 03:02:23 +000070
71/* ----------------------------------------------------------------------
72 * DSP object initialization/deallocation
73 */
74
Greg Ward499b73e2002-12-31 03:04:52 +000075static oss_audio_t *
Greg Ward8c6b6a92002-12-11 14:43:13 +000076newossobject(PyObject *arg)
Greg Ward04613a92002-11-30 22:47:45 +000077{
Greg Ward58ae13c2002-12-31 03:07:21 +000078 oss_audio_t *self;
Greg Ward04613a92002-11-30 22:47:45 +000079 int fd, afmts, imode;
Greg Ward50682d02005-03-07 01:41:11 +000080 char *devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000081 char *mode = NULL;
82
Greg Ward9a568eb2002-11-30 23:20:09 +000083 /* Two ways to call open():
Greg Ward04613a92002-11-30 22:47:45 +000084 open(device, mode) (for consistency with builtin open())
85 open(mode) (for backwards compatibility)
86 because the *first* argument is optional, parsing args is
87 a wee bit tricky. */
Greg Ward50682d02005-03-07 01:41:11 +000088 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
Greg Ward04613a92002-11-30 22:47:45 +000089 return NULL;
90 if (mode == NULL) { /* only one arg supplied */
Greg Ward50682d02005-03-07 01:41:11 +000091 mode = devicename;
92 devicename = NULL;
Greg Ward04613a92002-11-30 22:47:45 +000093 }
94
95 if (strcmp(mode, "r") == 0)
96 imode = O_RDONLY;
97 else if (strcmp(mode, "w") == 0)
98 imode = O_WRONLY;
Greg Ward1e0f57d2002-11-30 23:05:26 +000099 else if (strcmp(mode, "rw") == 0)
100 imode = O_RDWR;
Greg Ward04613a92002-11-30 22:47:45 +0000101 else {
Greg Ward97708bc2002-11-30 23:17:10 +0000102 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
Greg Ward04613a92002-11-30 22:47:45 +0000103 return NULL;
104 }
105
Greg Ward5c5c5772002-12-30 02:58:04 +0000106 /* Open the correct device: either the 'device' argument,
107 or the AUDIODEV environment variable, or "/dev/dsp". */
Greg Ward50682d02005-03-07 01:41:11 +0000108 if (devicename == NULL) { /* called with one arg */
109 devicename = getenv("AUDIODEV");
110 if (devicename == NULL) /* $AUDIODEV not set */
111 devicename = "/dev/dsp";
Greg Ward04613a92002-11-30 22:47:45 +0000112 }
113
Greg Ward5c49ef22003-03-11 16:53:13 +0000114 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
115 one open at a time. This does *not* affect later I/O; OSS
116 provides a special ioctl() for non-blocking read/write, which is
117 exposed via oss_nonblock() below. */
Greg Ward50682d02005-03-07 01:41:11 +0000118 if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) {
119 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000120 return NULL;
121 }
Greg Ward76ffb192003-04-04 01:47:42 +0000122
123 /* And (try to) put it back in blocking mode so we get the
124 expected write() semantics. */
125 if (fcntl(fd, F_SETFL, 0) == -1) {
126 close(fd);
Greg Ward50682d02005-03-07 01:41:11 +0000127 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward76ffb192003-04-04 01:47:42 +0000128 return NULL;
129 }
130
Greg Ward04613a92002-11-30 22:47:45 +0000131 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
Greg Ward50682d02005-03-07 01:41:11 +0000132 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward04613a92002-11-30 22:47:45 +0000133 return NULL;
134 }
135 /* Create and initialize the object */
Greg Ward58ae13c2002-12-31 03:07:21 +0000136 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
Greg Ward04613a92002-11-30 22:47:45 +0000137 close(fd);
138 return NULL;
139 }
Greg Ward50682d02005-03-07 01:41:11 +0000140 self->devicename = devicename;
Greg Ward58ae13c2002-12-31 03:07:21 +0000141 self->fd = fd;
142 self->mode = imode;
143 self->icount = self->ocount = 0;
144 self->afmts = afmts;
145 return self;
Greg Ward04613a92002-11-30 22:47:45 +0000146}
147
148static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000149oss_dealloc(oss_audio_t *self)
Greg Ward04613a92002-11-30 22:47:45 +0000150{
151 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000152 if (self->fd != -1)
153 close(self->fd);
154 PyObject_Del(self);
Greg Ward04613a92002-11-30 22:47:45 +0000155}
156
Greg Wardda1cacb2002-12-31 03:02:23 +0000157
158/* ----------------------------------------------------------------------
159 * Mixer object initialization/deallocation
160 */
161
Greg Ward3d9994d2002-12-11 15:12:01 +0000162static oss_mixer_t *
163newossmixerobject(PyObject *arg)
164{
Greg Ward50682d02005-03-07 01:41:11 +0000165 char *devicename = NULL;
Greg Ward0b6dfb82003-03-10 03:17:06 +0000166 int fd;
Greg Ward58ae13c2002-12-31 03:07:21 +0000167 oss_mixer_t *self;
Guido van Rossum0741f802003-06-02 14:15:34 +0000168
Greg Ward50682d02005-03-07 01:41:11 +0000169 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000170 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000171 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000172
Greg Ward50682d02005-03-07 01:41:11 +0000173 if (devicename == NULL) {
174 devicename = getenv("MIXERDEV");
175 if (devicename == NULL) /* MIXERDEV not set */
176 devicename = "/dev/mixer";
Greg Ward3d9994d2002-12-11 15:12:01 +0000177 }
178
Greg Ward50682d02005-03-07 01:41:11 +0000179 if ((fd = open(devicename, O_RDWR)) == -1) {
180 PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename);
Greg Ward3d9994d2002-12-11 15:12:01 +0000181 return NULL;
182 }
Greg Ward0b6dfb82003-03-10 03:17:06 +0000183
Greg Ward58ae13c2002-12-31 03:07:21 +0000184 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
Greg Ward3d9994d2002-12-11 15:12:01 +0000185 close(fd);
186 return NULL;
187 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000188
Greg Ward58ae13c2002-12-31 03:07:21 +0000189 self->fd = fd;
Guido van Rossum0741f802003-06-02 14:15:34 +0000190
Greg Ward58ae13c2002-12-31 03:07:21 +0000191 return self;
Greg Ward3d9994d2002-12-11 15:12:01 +0000192}
193
194static void
Greg Ward58ae13c2002-12-31 03:07:21 +0000195oss_mixer_dealloc(oss_mixer_t *self)
Greg Ward3d9994d2002-12-11 15:12:01 +0000196{
197 /* if already closed, don't reclose it */
Greg Ward58ae13c2002-12-31 03:07:21 +0000198 if (self->fd != -1)
199 close(self->fd);
200 PyObject_Del(self);
Greg Ward3d9994d2002-12-11 15:12:01 +0000201}
202
Greg Ward131bce02002-11-30 22:56:44 +0000203
204/* Methods to wrap the OSS ioctls. The calling convention is pretty
205 simple:
206 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
207 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
208 etc.
209*/
210
211
Greg Wardd6769062003-05-29 21:53:06 +0000212/* ----------------------------------------------------------------------
213 * Helper functions
214 */
215
Greg Ward131bce02002-11-30 22:56:44 +0000216/* _do_ioctl_1() is a private helper function used for the OSS ioctls --
217 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that that are called from C
218 like this:
219 ioctl(fd, SNDCTL_DSP_cmd, &arg)
220
221 where arg is the value to set, and on return the driver sets arg to
222 the value that was actually set. Mapping this to Python is obvious:
223 arg = dsp.xxx(arg)
224*/
225static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000226_do_ioctl_1(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000227{
Greg Wardda9f8532002-12-11 14:49:59 +0000228 char argfmt[33] = "i:";
Greg Ward131bce02002-11-30 22:56:44 +0000229 int arg;
230
Greg Wardda9f8532002-12-11 14:49:59 +0000231 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000232 strcat(argfmt, fname);
233 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000234 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000235
Greg Wardda9f8532002-12-11 14:49:59 +0000236 if (ioctl(fd, cmd, &arg) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000237 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000238 return PyInt_FromLong(arg);
239}
240
Greg Wardda1cacb2002-12-31 03:02:23 +0000241
Greg Ward3d9994d2002-12-11 15:12:01 +0000242/* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
243 but return an output -- ie. we need to pass a pointer to a local C
244 variable so the driver can write its output there, but from Python
245 all we see is the return value. For example,
246 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
247 devices, but does not use the value of the parameter passed-in in any
248 way.
249*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000250static PyObject *
251_do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd)
252{
253 char argfmt[32] = ":";
254 int arg = 0;
255
256 assert(strlen(fname) <= 30);
257 strcat(argfmt, fname);
258 if (!PyArg_ParseTuple(args, argfmt, &arg))
Greg Wardad4d9b92002-12-30 03:02:22 +0000259 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000260
261 if (ioctl(fd, cmd, &arg) == -1)
262 return PyErr_SetFromErrno(PyExc_IOError);
263 return PyInt_FromLong(arg);
264}
265
266
267
Greg Ward131bce02002-11-30 22:56:44 +0000268/* _do_ioctl_0() is a private helper for the no-argument ioctls:
269 SNDCTL_DSP_{SYNC,RESET,POST}. */
270static PyObject *
Greg Wardda9f8532002-12-11 14:49:59 +0000271_do_ioctl_0(int fd, PyObject *args, char *fname, int cmd)
Greg Ward131bce02002-11-30 22:56:44 +0000272{
Greg Wardda9f8532002-12-11 14:49:59 +0000273 char argfmt[32] = ":";
Greg Wardd0d592f2003-05-27 01:57:21 +0000274 int rv;
Greg Ward131bce02002-11-30 22:56:44 +0000275
Greg Wardda9f8532002-12-11 14:49:59 +0000276 assert(strlen(fname) <= 30);
Greg Ward131bce02002-11-30 22:56:44 +0000277 strcat(argfmt, fname);
278 if (!PyArg_ParseTuple(args, argfmt))
Greg Wardad4d9b92002-12-30 03:02:22 +0000279 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000280
Greg Wardd0d592f2003-05-27 01:57:21 +0000281 /* According to hannu@opensound.com, all three of the ioctls that
282 use this function can block, so release the GIL. This is
283 especially important for SYNC, which can block for several
284 seconds. */
285 Py_BEGIN_ALLOW_THREADS
286 rv = ioctl(fd, cmd, 0);
287 Py_END_ALLOW_THREADS
288
289 if (rv == -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
Greg Wardda1cacb2002-12-31 03:02:23 +0000296/* ----------------------------------------------------------------------
Greg Ward499b73e2002-12-31 03:04:52 +0000297 * Methods of DSP objects (OSSAudioType)
Greg Wardda1cacb2002-12-31 03:02:23 +0000298 */
299
Greg Ward131bce02002-11-30 22:56:44 +0000300static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000301oss_nonblock(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000302{
303 /* Hmmm: it doesn't appear to be possible to return to blocking
304 mode once we're in non-blocking mode! */
Greg Ward7b43c682002-12-30 02:29:28 +0000305 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000306 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000307 Py_INCREF(Py_None);
308 return Py_None;
309}
310
311static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000312oss_setfmt(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000313{
Greg Ward7b43c682002-12-30 02:29:28 +0000314 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
Greg Ward131bce02002-11-30 22:56:44 +0000315}
316
317static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000318oss_getfmts(oss_audio_t *self, PyObject *unused)
Greg Ward131bce02002-11-30 22:56:44 +0000319{
320 int mask;
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 Ward499b73e2002-12-31 03:04:52 +0000327oss_channels(oss_audio_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 Ward499b73e2002-12-31 03:04:52 +0000333oss_speed(oss_audio_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 Ward499b73e2002-12-31 03:04:52 +0000339oss_sync(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000340{
Greg Wardd0d592f2003-05-27 01:57:21 +0000341 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
Greg Ward131bce02002-11-30 22:56:44 +0000342}
Guido van Rossum0741f802003-06-02 14:15:34 +0000343
Greg Ward131bce02002-11-30 22:56:44 +0000344static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000345oss_reset(oss_audio_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}
Guido van Rossum0741f802003-06-02 14:15:34 +0000349
Greg Ward131bce02002-11-30 22:56:44 +0000350static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000351oss_post(oss_audio_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 Ward499b73e2002-12-31 03:04:52 +0000361oss_read(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000362{
363 int size, count;
364 char *cp;
365 PyObject *rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000366
Greg Ward04613a92002-11-30 22:47:45 +0000367 if (!PyArg_ParseTuple(args, "i:read", &size))
368 return NULL;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000369 rv = PyString_FromStringAndSize(NULL, size);
Greg Ward04613a92002-11-30 22:47:45 +0000370 if (rv == NULL)
371 return NULL;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000372 cp = PyString_AS_STRING(rv);
Greg Ward64927852003-05-23 01:50:37 +0000373
374 Py_BEGIN_ALLOW_THREADS
375 count = read(self->fd, cp, size);
376 Py_END_ALLOW_THREADS
377
378 if (count < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000379 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000380 Py_DECREF(rv);
381 return NULL;
382 }
Greg Ward7b43c682002-12-30 02:29:28 +0000383 self->icount += count;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000384 _PyString_Resize(&rv, count);
Greg Ward04613a92002-11-30 22:47:45 +0000385 return rv;
386}
387
388static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000389oss_write(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000390{
391 char *cp;
392 int rv, size;
Greg Ward131bce02002-11-30 22:56:44 +0000393
394 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000395 return NULL;
Greg Ward131bce02002-11-30 22:56:44 +0000396 }
Greg Ward64927852003-05-23 01:50:37 +0000397
398 Py_BEGIN_ALLOW_THREADS
399 rv = write(self->fd, cp, size);
400 Py_END_ALLOW_THREADS
401
402 if (rv == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000403 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000404 } else {
Greg Ward7b43c682002-12-30 02:29:28 +0000405 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000406 }
407 return PyInt_FromLong(rv);
408}
409
410static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000411oss_writeall(oss_audio_t *self, PyObject *args)
Greg Ward131bce02002-11-30 22:56:44 +0000412{
413 char *cp;
414 int rv, size;
415 fd_set write_set_fds;
416 int select_rv;
Guido van Rossum0741f802003-06-02 14:15:34 +0000417
Greg Ward131bce02002-11-30 22:56:44 +0000418 /* NB. writeall() is only useful in non-blocking mode: according to
419 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
420 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
421 write() in blocking mode consumes the whole buffer. In blocking
422 mode, the behaviour of write() and writeall() from Python is
423 indistinguishable. */
424
Guido van Rossum0741f802003-06-02 14:15:34 +0000425 if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
Greg Ward131bce02002-11-30 22:56:44 +0000426 return NULL;
Greg Ward04613a92002-11-30 22:47:45 +0000427
Charles-François Natalifda7b372011-08-28 16:22:33 +0200428 if (!_PyIsSelectable_fd(self->fd)) {
429 PyErr_SetString(PyExc_ValueError,
430 "file descriptor out of range for select");
431 return NULL;
432 }
Greg Ward04613a92002-11-30 22:47:45 +0000433 /* use select to wait for audio device to be available */
434 FD_ZERO(&write_set_fds);
Greg Ward7b43c682002-12-30 02:29:28 +0000435 FD_SET(self->fd, &write_set_fds);
Greg Ward04613a92002-11-30 22:47:45 +0000436
437 while (size > 0) {
Greg Ward64927852003-05-23 01:50:37 +0000438 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000439 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
Greg Ward64927852003-05-23 01:50:37 +0000440 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000441 assert(select_rv != 0); /* no timeout, can't expire */
442 if (select_rv == -1)
Greg Ward97708bc2002-11-30 23:17:10 +0000443 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000444
Greg Ward64927852003-05-23 01:50:37 +0000445 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000446 rv = write(self->fd, cp, size);
Greg Ward64927852003-05-23 01:50:37 +0000447 Py_END_ALLOW_THREADS
Greg Ward131bce02002-11-30 22:56:44 +0000448 if (rv == -1) {
449 if (errno == EAGAIN) { /* buffer is full, try again */
450 errno = 0;
451 continue;
452 } else /* it's a real error */
Greg Ward97708bc2002-11-30 23:17:10 +0000453 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward131bce02002-11-30 22:56:44 +0000454 } else { /* wrote rv bytes */
Greg Ward7b43c682002-12-30 02:29:28 +0000455 self->ocount += rv;
Greg Ward131bce02002-11-30 22:56:44 +0000456 size -= rv;
457 cp += rv;
458 }
Greg Ward04613a92002-11-30 22:47:45 +0000459 }
460 Py_INCREF(Py_None);
461 return Py_None;
462}
463
464static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000465oss_close(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000466{
Greg Ward7b43c682002-12-30 02:29:28 +0000467 if (self->fd >= 0) {
Greg Wardb8043902003-05-26 22:47:30 +0000468 Py_BEGIN_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000469 close(self->fd);
Greg Wardb8043902003-05-26 22:47:30 +0000470 Py_END_ALLOW_THREADS
Greg Ward7b43c682002-12-30 02:29:28 +0000471 self->fd = -1;
Greg Ward04613a92002-11-30 22:47:45 +0000472 }
473 Py_INCREF(Py_None);
474 return Py_None;
475}
476
477static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000478oss_fileno(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000479{
Greg Ward7b43c682002-12-30 02:29:28 +0000480 return PyInt_FromLong(self->fd);
Greg Ward04613a92002-11-30 22:47:45 +0000481}
482
Greg Ward131bce02002-11-30 22:56:44 +0000483
484/* Convenience methods: these generally wrap a couple of ioctls into one
485 common task. */
486
Greg Ward04613a92002-11-30 22:47:45 +0000487static PyObject *
Greg Ward499b73e2002-12-31 03:04:52 +0000488oss_setparameters(oss_audio_t *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000489{
Greg Wardd6769062003-05-29 21:53:06 +0000490 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
491 int fmt, channels, rate;
492 PyObject * rv; /* return tuple (fmt, channels, rate) */
Greg Ward04613a92002-11-30 22:47:45 +0000493
Greg Wardd6769062003-05-29 21:53:06 +0000494 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
495 &wanted_fmt, &wanted_channels, &wanted_rate,
496 &strict))
Greg Ward04613a92002-11-30 22:47:45 +0000497 return NULL;
Greg Wardd6769062003-05-29 21:53:06 +0000498
499 fmt = wanted_fmt;
500 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
501 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000502 }
Greg Wardd6769062003-05-29 21:53:06 +0000503 if (strict && fmt != wanted_fmt) {
504 return PyErr_Format
505 (OSSAudioError,
506 "unable to set requested format (wanted %d, got %d)",
507 wanted_fmt, fmt);
Greg Ward04613a92002-11-30 22:47:45 +0000508 }
509
Greg Wardd6769062003-05-29 21:53:06 +0000510 channels = wanted_channels;
511 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
512 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000513 }
Greg Wardd6769062003-05-29 21:53:06 +0000514 if (strict && channels != wanted_channels) {
515 return PyErr_Format
516 (OSSAudioError,
517 "unable to set requested channels (wanted %d, got %d)",
518 wanted_channels, channels);
Greg Ward04613a92002-11-30 22:47:45 +0000519 }
520
Greg Wardd6769062003-05-29 21:53:06 +0000521 rate = wanted_rate;
Greg Ward7b43c682002-12-30 02:29:28 +0000522 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
Greg Wardd6769062003-05-29 21:53:06 +0000523 return PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000524 }
Greg Wardd6769062003-05-29 21:53:06 +0000525 if (strict && rate != wanted_rate) {
526 return PyErr_Format
527 (OSSAudioError,
528 "unable to set requested rate (wanted %d, got %d)",
529 wanted_rate, rate);
530 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000531
Greg Wardd6769062003-05-29 21:53:06 +0000532 /* Construct the return value: a (fmt, channels, rate) tuple that
533 tells what the audio hardware was actually set to. */
534 rv = PyTuple_New(3);
535 if (rv == NULL)
536 return NULL;
537 PyTuple_SET_ITEM(rv, 0, PyInt_FromLong(fmt));
538 PyTuple_SET_ITEM(rv, 1, PyInt_FromLong(channels));
539 PyTuple_SET_ITEM(rv, 2, PyInt_FromLong(rate));
540 return rv;
Greg Ward04613a92002-11-30 22:47:45 +0000541}
542
543static int
Greg Ward499b73e2002-12-31 03:04:52 +0000544_ssize(oss_audio_t *self, int *nchannels, int *ssize)
Greg Ward04613a92002-11-30 22:47:45 +0000545{
546 int fmt;
547
548 fmt = 0;
Guido van Rossum0741f802003-06-02 14:15:34 +0000549 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000550 return -errno;
551
552 switch (fmt) {
553 case AFMT_MU_LAW:
554 case AFMT_A_LAW:
555 case AFMT_U8:
556 case AFMT_S8:
Greg Ward38c92662003-05-29 21:55:41 +0000557 *ssize = 1; /* 8 bit formats: 1 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000558 break;
559 case AFMT_S16_LE:
560 case AFMT_S16_BE:
561 case AFMT_U16_LE:
562 case AFMT_U16_BE:
Greg Ward84f8ecd2003-05-29 23:44:44 +0000563 *ssize = 2; /* 16 bit formats: 2 byte */
Greg Ward04613a92002-11-30 22:47:45 +0000564 break;
565 case AFMT_MPEG:
566 case AFMT_IMA_ADPCM:
567 default:
568 return -EOPNOTSUPP;
569 }
Greg Ward7b43c682002-12-30 02:29:28 +0000570 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
Greg Ward04613a92002-11-30 22:47:45 +0000571 return -errno;
572 return 0;
573}
574
575
Guido van Rossum0741f802003-06-02 14:15:34 +0000576/* bufsize returns the size of the hardware audio buffer in number
Greg Ward04613a92002-11-30 22:47:45 +0000577 of samples */
578static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000579oss_bufsize(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000580{
581 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000582 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000583
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000584 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000585 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000586 return NULL;
587 }
Greg Ward7b43c682002-12-30 02:29:28 +0000588 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000589 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000590 return NULL;
591 }
592 return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
593}
594
Guido van Rossum0741f802003-06-02 14:15:34 +0000595/* obufcount returns the number of samples that are available in the
Greg Ward04613a92002-11-30 22:47:45 +0000596 hardware for playing */
597static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000598oss_obufcount(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000599{
600 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000601 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000602
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000603 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000604 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000605 return NULL;
606 }
Greg Ward7b43c682002-12-30 02:29:28 +0000607 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000608 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000609 return NULL;
610 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000611 return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
Greg Ward04613a92002-11-30 22:47:45 +0000612 (ssize * nchannels));
613}
614
615/* obufcount returns the number of samples that can be played without
616 blocking */
617static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000618oss_obuffree(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000619{
620 audio_buf_info ai;
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000621 int nchannels=0, ssize=0;
Greg Ward04613a92002-11-30 22:47:45 +0000622
Thomas Wouters3ffa59b2006-03-01 22:45:36 +0000623 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
Greg Ward97708bc2002-11-30 23:17:10 +0000624 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000625 return NULL;
626 }
Greg Ward7b43c682002-12-30 02:29:28 +0000627 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
Greg Ward97708bc2002-11-30 23:17:10 +0000628 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000629 return NULL;
630 }
631 return PyInt_FromLong(ai.bytes / (ssize * nchannels));
632}
633
Greg Ward04613a92002-11-30 22:47:45 +0000634static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000635oss_getptr(oss_audio_t *self, PyObject *unused)
Greg Ward04613a92002-11-30 22:47:45 +0000636{
637 count_info info;
638 int req;
639
Greg Ward7b43c682002-12-30 02:29:28 +0000640 if (self->mode == O_RDONLY)
Greg Wardad4d9b92002-12-30 03:02:22 +0000641 req = SNDCTL_DSP_GETIPTR;
Greg Ward04613a92002-11-30 22:47:45 +0000642 else
Greg Wardad4d9b92002-12-30 03:02:22 +0000643 req = SNDCTL_DSP_GETOPTR;
Greg Ward7b43c682002-12-30 02:29:28 +0000644 if (ioctl(self->fd, req, &info) == -1) {
Greg Ward97708bc2002-11-30 23:17:10 +0000645 PyErr_SetFromErrno(PyExc_IOError);
Greg Ward04613a92002-11-30 22:47:45 +0000646 return NULL;
647 }
648 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
649}
650
Greg Wardda1cacb2002-12-31 03:02:23 +0000651
652/* ----------------------------------------------------------------------
653 * Methods of mixer objects (OSSMixerType)
654 */
655
Greg Ward3d9994d2002-12-11 15:12:01 +0000656static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000657oss_mixer_close(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000658{
Greg Ward7b43c682002-12-30 02:29:28 +0000659 if (self->fd >= 0) {
660 close(self->fd);
661 self->fd = -1;
Greg Ward3d9994d2002-12-11 15:12:01 +0000662 }
663 Py_INCREF(Py_None);
664 return Py_None;
665}
666
667static PyObject *
Georg Brandl96a8c392006-05-29 21:04:52 +0000668oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
Greg Ward3d9994d2002-12-11 15:12:01 +0000669{
Greg Ward7b43c682002-12-30 02:29:28 +0000670 return PyInt_FromLong(self->fd);
Greg Ward3d9994d2002-12-11 15:12:01 +0000671}
672
673/* Simple mixer interface methods */
674
675static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000676oss_mixer_controls(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000677{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000678 return _do_ioctl_1_internal(self->fd, args, "controls",
Greg Ward3d9994d2002-12-11 15:12:01 +0000679 SOUND_MIXER_READ_DEVMASK);
680}
681
682static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000683oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000684{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000685 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
Greg Ward3d9994d2002-12-11 15:12:01 +0000686 SOUND_MIXER_READ_STEREODEVS);
687}
688
689static PyObject *
Greg Ward2d6f9a92002-12-31 02:54:43 +0000690oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000691{
Greg Ward2d6f9a92002-12-31 02:54:43 +0000692 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
Greg Wardb69bb3d2002-12-12 17:35:45 +0000693 SOUND_MIXER_READ_RECMASK);
Greg Ward3d9994d2002-12-11 15:12:01 +0000694}
695
696static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000697oss_mixer_get(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000698{
699 int channel, volume;
Guido van Rossum0741f802003-06-02 14:15:34 +0000700
Greg Ward3d9994d2002-12-11 15:12:01 +0000701 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000702 if (!PyArg_ParseTuple(args, "i:get", &channel))
Greg Wardad4d9b92002-12-30 03:02:22 +0000703 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000704
Greg Ward3d9994d2002-12-11 15:12:01 +0000705 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000706 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
707 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000708 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000709
Greg Warde7037662002-12-30 03:01:48 +0000710 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000711 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000712
Greg Warde7037662002-12-30 03:01:48 +0000713 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000714}
715
716static PyObject *
Greg Warde7037662002-12-30 03:01:48 +0000717oss_mixer_set(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000718{
719 int channel, volume, leftVol, rightVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000720
Greg Ward3d9994d2002-12-11 15:12:01 +0000721 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
Greg Warde7037662002-12-30 03:01:48 +0000722 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
Greg Wardad4d9b92002-12-30 03:02:22 +0000723 return NULL;
Guido van Rossum0741f802003-06-02 14:15:34 +0000724
Greg Ward3d9994d2002-12-11 15:12:01 +0000725 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000726 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
727 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000728 }
Guido van Rossum0741f802003-06-02 14:15:34 +0000729
Greg Ward3d9994d2002-12-11 15:12:01 +0000730 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
Greg Wardad4d9b92002-12-30 03:02:22 +0000731 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
732 return NULL;
Greg Ward3d9994d2002-12-11 15:12:01 +0000733 }
734
735 volume = (rightVol << 8) | leftVol;
Guido van Rossum0741f802003-06-02 14:15:34 +0000736
Greg Warde7037662002-12-30 03:01:48 +0000737 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
Greg Wardad4d9b92002-12-30 03:02:22 +0000738 return PyErr_SetFromErrno(PyExc_IOError);
Guido van Rossum0741f802003-06-02 14:15:34 +0000739
Greg Warde7037662002-12-30 03:01:48 +0000740 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
Greg Ward3d9994d2002-12-11 15:12:01 +0000741}
742
743static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000744oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000745{
Greg Wardf05aa102002-12-30 23:19:32 +0000746 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000747 SOUND_MIXER_READ_RECSRC);
748}
749
750static PyObject *
Greg Wardf05aa102002-12-30 23:19:32 +0000751oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
Greg Ward3d9994d2002-12-11 15:12:01 +0000752{
Greg Wardf05aa102002-12-30 23:19:32 +0000753 return _do_ioctl_1(self->fd, args, "set_recsrc",
Greg Ward3d9994d2002-12-11 15:12:01 +0000754 SOUND_MIXER_WRITE_RECSRC);
755}
756
757
Greg Wardda1cacb2002-12-31 03:02:23 +0000758/* ----------------------------------------------------------------------
759 * Method tables and other bureaucracy
760 */
761
Greg Ward8c6b6a92002-12-11 14:43:13 +0000762static PyMethodDef oss_methods[] = {
Greg Ward131bce02002-11-30 22:56:44 +0000763 /* Regular file methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000764 { "read", (PyCFunction)oss_read, METH_VARARGS },
765 { "write", (PyCFunction)oss_write, METH_VARARGS },
766 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000767 { "close", (PyCFunction)oss_close, METH_NOARGS },
768 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000769
770 /* Simple ioctl wrappers */
Georg Brandl96a8c392006-05-29 21:04:52 +0000771 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000772 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000773 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
Greg Ward8c6b6a92002-12-11 14:43:13 +0000774 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
775 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
Greg Wardad4d9b92002-12-30 03:02:22 +0000776 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
777 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
778 { "post", (PyCFunction)oss_post, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000779
780 /* Convenience methods -- wrap a couple of ioctls together */
Greg Wardad4d9b92002-12-30 03:02:22 +0000781 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
Georg Brandl96a8c392006-05-29 21:04:52 +0000782 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
783 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
784 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
785 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000786
787 /* Aliases for backwards compatibility */
Greg Wardad4d9b92002-12-30 03:02:22 +0000788 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
Greg Ward131bce02002-11-30 22:56:44 +0000789
Greg Wardad4d9b92002-12-30 03:02:22 +0000790 { NULL, NULL} /* sentinel */
Greg Ward04613a92002-11-30 22:47:45 +0000791};
792
Greg Ward3d9994d2002-12-11 15:12:01 +0000793static PyMethodDef oss_mixer_methods[] = {
794 /* Regular file method - OSS mixers are ioctl-only interface */
Georg Brandl96a8c392006-05-29 21:04:52 +0000795 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
796 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000797
798 /* Simple ioctl wrappers */
Guido van Rossum0741f802003-06-02 14:15:34 +0000799 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
Greg Ward2d6f9a92002-12-31 02:54:43 +0000800 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
Guido van Rossum0741f802003-06-02 14:15:34 +0000801 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
Greg Wardad4d9b92002-12-30 03:02:22 +0000802 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
803 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
Greg Wardf05aa102002-12-30 23:19:32 +0000804 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
805 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
Guido van Rossum0741f802003-06-02 14:15:34 +0000806
Greg Wardad4d9b92002-12-30 03:02:22 +0000807 { NULL, NULL}
Greg Ward3d9994d2002-12-11 15:12:01 +0000808};
809
Greg Ward04613a92002-11-30 22:47:45 +0000810static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000811oss_getattr(oss_audio_t *self, char *name)
Greg Ward04613a92002-11-30 22:47:45 +0000812{
Greg Ward50682d02005-03-07 01:41:11 +0000813 PyObject * rval = NULL;
814 if (strcmp(name, "closed") == 0) {
815 rval = (self->fd == -1) ? Py_True : Py_False;
816 Py_INCREF(rval);
817 }
818 else if (strcmp(name, "name") == 0) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000819 rval = PyString_FromString(self->devicename);
Greg Ward50682d02005-03-07 01:41:11 +0000820 }
821 else if (strcmp(name, "mode") == 0) {
822 /* No need for a "default" in this switch: from newossobject(),
823 self->mode can only be one of these three values. */
824 switch(self->mode) {
825 case O_RDONLY:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000826 rval = PyString_FromString("r");
Greg Ward50682d02005-03-07 01:41:11 +0000827 break;
828 case O_RDWR:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000829 rval = PyString_FromString("rw");
Greg Ward50682d02005-03-07 01:41:11 +0000830 break;
831 case O_WRONLY:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000832 rval = PyString_FromString("w");
Greg Ward50682d02005-03-07 01:41:11 +0000833 break;
834 }
835 }
836 else {
837 rval = Py_FindMethod(oss_methods, (PyObject *)self, name);
838 }
839 return rval;
Greg Ward04613a92002-11-30 22:47:45 +0000840}
841
Greg Ward3d9994d2002-12-11 15:12:01 +0000842static PyObject *
Greg Ward58ae13c2002-12-31 03:07:21 +0000843oss_mixer_getattr(oss_mixer_t *self, char *name)
Greg Ward3d9994d2002-12-11 15:12:01 +0000844{
Greg Ward58ae13c2002-12-31 03:07:21 +0000845 return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name);
Greg Ward3d9994d2002-12-11 15:12:01 +0000846}
847
Greg Ward499b73e2002-12-31 03:04:52 +0000848static PyTypeObject OSSAudioType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000849 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward9a568eb2002-11-30 23:20:09 +0000850 "ossaudiodev.oss_audio_device", /*tp_name*/
Greg Ward499b73e2002-12-31 03:04:52 +0000851 sizeof(oss_audio_t), /*tp_size*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000852 0, /*tp_itemsize*/
Greg Ward04613a92002-11-30 22:47:45 +0000853 /* methods */
Greg Wardad4d9b92002-12-30 03:02:22 +0000854 (destructor)oss_dealloc, /*tp_dealloc*/
855 0, /*tp_print*/
856 (getattrfunc)oss_getattr, /*tp_getattr*/
857 0, /*tp_setattr*/
858 0, /*tp_compare*/
859 0, /*tp_repr*/
Greg Ward04613a92002-11-30 22:47:45 +0000860};
861
Greg Ward3d9994d2002-12-11 15:12:01 +0000862static PyTypeObject OSSMixerType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000863 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Greg Ward3d9994d2002-12-11 15:12:01 +0000864 "ossaudiodev.oss_mixer_device", /*tp_name*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000865 sizeof(oss_mixer_t), /*tp_size*/
866 0, /*tp_itemsize*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000867 /* methods */
868 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000869 0, /*tp_print*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000870 (getattrfunc)oss_mixer_getattr, /*tp_getattr*/
Greg Wardad4d9b92002-12-30 03:02:22 +0000871 0, /*tp_setattr*/
872 0, /*tp_compare*/
873 0, /*tp_repr*/
Greg Ward3d9994d2002-12-11 15:12:01 +0000874};
875
876
Greg Ward04613a92002-11-30 22:47:45 +0000877static PyObject *
Greg Ward9a568eb2002-11-30 23:20:09 +0000878ossopen(PyObject *self, PyObject *args)
Greg Ward04613a92002-11-30 22:47:45 +0000879{
Greg Ward8c6b6a92002-12-11 14:43:13 +0000880 return (PyObject *)newossobject(args);
Greg Ward04613a92002-11-30 22:47:45 +0000881}
882
Greg Ward3d9994d2002-12-11 15:12:01 +0000883static PyObject *
884ossopenmixer(PyObject *self, PyObject *args)
885{
886 return (PyObject *)newossmixerobject(args);
887}
888
Greg Ward9a568eb2002-11-30 23:20:09 +0000889static PyMethodDef ossaudiodev_methods[] = {
890 { "open", ossopen, METH_VARARGS },
Greg Ward3d9994d2002-12-11 15:12:01 +0000891 { "openmixer", ossopenmixer, METH_VARARGS },
Greg Ward04613a92002-11-30 22:47:45 +0000892 { 0, 0 },
893};
894
Greg Ward1e0f57d2002-11-30 23:05:26 +0000895
896#define _EXPORT_INT(mod, name) \
897 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return;
898
Greg Ward744f0fd2002-12-31 03:23:59 +0000899
900static char *control_labels[] = SOUND_DEVICE_LABELS;
901static char *control_names[] = SOUND_DEVICE_NAMES;
902
903
904static int
905build_namelists (PyObject *module)
906{
907 PyObject *labels;
908 PyObject *names;
909 PyObject *s;
910 int num_controls;
911 int i;
912
913 num_controls = sizeof(control_labels) / sizeof(control_labels[0]);
914 assert(num_controls == sizeof(control_names) / sizeof(control_names[0]));
915
916 labels = PyList_New(num_controls);
917 names = PyList_New(num_controls);
Georg Brandl5c170fd2006-03-17 19:03:25 +0000918 if (labels == NULL || names == NULL)
919 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000920 for (i = 0; i < num_controls; i++) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000921 s = PyString_FromString(control_labels[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000922 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000923 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000924 PyList_SET_ITEM(labels, i, s);
Guido van Rossum0741f802003-06-02 14:15:34 +0000925
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000926 s = PyString_FromString(control_names[i]);
Greg Ward744f0fd2002-12-31 03:23:59 +0000927 if (s == NULL)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000928 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000929 PyList_SET_ITEM(names, i, s);
930 }
931
932 if (PyModule_AddObject(module, "control_labels", labels) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000933 goto error2;
Greg Ward744f0fd2002-12-31 03:23:59 +0000934 if (PyModule_AddObject(module, "control_names", names) == -1)
Georg Brandl5c170fd2006-03-17 19:03:25 +0000935 goto error1;
Greg Ward744f0fd2002-12-31 03:23:59 +0000936
937 return 0;
Georg Brandl5c170fd2006-03-17 19:03:25 +0000938
939error2:
940 Py_XDECREF(labels);
941error1:
942 Py_XDECREF(names);
943 return -1;
Guido van Rossum0741f802003-06-02 14:15:34 +0000944}
Greg Ward744f0fd2002-12-31 03:23:59 +0000945
946
Greg Ward04613a92002-11-30 22:47:45 +0000947void
Greg Ward9a568eb2002-11-30 23:20:09 +0000948initossaudiodev(void)
Greg Ward04613a92002-11-30 22:47:45 +0000949{
950 PyObject *m;
Guido van Rossum0741f802003-06-02 14:15:34 +0000951
Greg Ward9a568eb2002-11-30 23:20:09 +0000952 m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
Neal Norwitz1ac754f2006-01-19 06:09:39 +0000953 if (m == NULL)
954 return;
Greg Ward04613a92002-11-30 22:47:45 +0000955
Guido van Rossum0741f802003-06-02 14:15:34 +0000956 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
957 NULL, NULL);
Greg Wardd6769062003-05-29 21:53:06 +0000958 if (OSSAudioError) {
Guido van Rossum0741f802003-06-02 14:15:34 +0000959 /* Each call to PyModule_AddObject decrefs it; compensate: */
960 Py_INCREF(OSSAudioError);
961 Py_INCREF(OSSAudioError);
Greg Wardad4d9b92002-12-30 03:02:22 +0000962 PyModule_AddObject(m, "error", OSSAudioError);
Greg Wardd6769062003-05-29 21:53:06 +0000963 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
964 }
Greg Ward04613a92002-11-30 22:47:45 +0000965
Greg Ward744f0fd2002-12-31 03:23:59 +0000966 /* Build 'control_labels' and 'control_names' lists and add them
967 to the module. */
968 if (build_namelists(m) == -1) /* XXX what to do here? */
969 return;
970
Greg Ward1e0f57d2002-11-30 23:05:26 +0000971 /* Expose the audio format numbers -- essential! */
972 _EXPORT_INT(m, AFMT_QUERY);
973 _EXPORT_INT(m, AFMT_MU_LAW);
974 _EXPORT_INT(m, AFMT_A_LAW);
975 _EXPORT_INT(m, AFMT_IMA_ADPCM);
976 _EXPORT_INT(m, AFMT_U8);
977 _EXPORT_INT(m, AFMT_S16_LE);
978 _EXPORT_INT(m, AFMT_S16_BE);
979 _EXPORT_INT(m, AFMT_S8);
980 _EXPORT_INT(m, AFMT_U16_LE);
981 _EXPORT_INT(m, AFMT_U16_BE);
982 _EXPORT_INT(m, AFMT_MPEG);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000983#ifdef AFMT_AC3
Greg Ward1e0f57d2002-11-30 23:05:26 +0000984 _EXPORT_INT(m, AFMT_AC3);
Andrew M. Kuchlingfe62bc92003-02-13 13:27:07 +0000985#endif
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000986#ifdef AFMT_S16_NE
Greg Ward1e0f57d2002-11-30 23:05:26 +0000987 _EXPORT_INT(m, AFMT_S16_NE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +0000988#endif
Greg Ward0f260542005-03-28 02:40:46 +0000989#ifdef AFMT_U16_NE
990 _EXPORT_INT(m, AFMT_U16_NE);
991#endif
992#ifdef AFMT_S32_LE
993 _EXPORT_INT(m, AFMT_S32_LE);
994#endif
995#ifdef AFMT_S32_BE
996 _EXPORT_INT(m, AFMT_S32_BE);
997#endif
998#ifdef AFMT_MPEG
999 _EXPORT_INT(m, AFMT_MPEG);
1000#endif
Guido van Rossum0741f802003-06-02 14:15:34 +00001001
Greg Ward37897c22002-12-30 02:43:36 +00001002 /* Expose the sound mixer device numbers. */
Greg Ward7b43c682002-12-30 02:29:28 +00001003 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
Greg Ward3d9994d2002-12-11 15:12:01 +00001004 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1005 _EXPORT_INT(m, SOUND_MIXER_BASS);
1006 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1007 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1008 _EXPORT_INT(m, SOUND_MIXER_PCM);
1009 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1010 _EXPORT_INT(m, SOUND_MIXER_LINE);
1011 _EXPORT_INT(m, SOUND_MIXER_MIC);
1012 _EXPORT_INT(m, SOUND_MIXER_CD);
1013 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1014 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1015 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1016 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1017 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1018 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1019 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1020 _EXPORT_INT(m, SOUND_MIXER_LINE3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001021#ifdef SOUND_MIXER_DIGITAL1
Greg Ward3d9994d2002-12-11 15:12:01 +00001022 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
Greg Wardfd0283e2004-05-11 01:34:55 +00001023#endif
1024#ifdef SOUND_MIXER_DIGITAL2
Greg Ward3d9994d2002-12-11 15:12:01 +00001025 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
Greg Wardfd0283e2004-05-11 01:34:55 +00001026#endif
1027#ifdef SOUND_MIXER_DIGITAL3
Greg Ward3d9994d2002-12-11 15:12:01 +00001028 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
Greg Wardfd0283e2004-05-11 01:34:55 +00001029#endif
1030#ifdef SOUND_MIXER_PHONEIN
Greg Ward3d9994d2002-12-11 15:12:01 +00001031 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
Greg Wardfd0283e2004-05-11 01:34:55 +00001032#endif
1033#ifdef SOUND_MIXER_PHONEOUT
Greg Ward3d9994d2002-12-11 15:12:01 +00001034 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
Greg Wardfd0283e2004-05-11 01:34:55 +00001035#endif
1036#ifdef SOUND_MIXER_VIDEO
Greg Ward3d9994d2002-12-11 15:12:01 +00001037 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001038#endif
1039#ifdef SOUND_MIXER_RADIO
Greg Ward3d9994d2002-12-11 15:12:01 +00001040 _EXPORT_INT(m, SOUND_MIXER_RADIO);
Greg Wardfd0283e2004-05-11 01:34:55 +00001041#endif
1042#ifdef SOUND_MIXER_MONITOR
Greg Ward3d9994d2002-12-11 15:12:01 +00001043 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
Greg Wardfd0283e2004-05-11 01:34:55 +00001044#endif
Greg Ward04613a92002-11-30 22:47:45 +00001045
Greg Ward1e0f57d2002-11-30 23:05:26 +00001046 /* Expose all the ioctl numbers for masochists who like to do this
1047 stuff directly. */
1048 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1049 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1050 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1051 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1052 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1053 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1054 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1055 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1056 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1057 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001058#ifdef SNDCTL_DSP_BIND_CHANNEL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001059 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001060#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001061 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1062 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1063 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001064#ifdef SNDCTL_DSP_GETCHANNELMASK
Greg Ward1e0f57d2002-11-30 23:05:26 +00001065 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001066#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001067 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1068 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1069 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
Greg Wardfd0283e2004-05-11 01:34:55 +00001070#ifdef SNDCTL_DSP_GETODELAY
Greg Ward1e0f57d2002-11-30 23:05:26 +00001071 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
Greg Wardfd0283e2004-05-11 01:34:55 +00001072#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001073 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1074 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001075#ifdef SNDCTL_DSP_GETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001076 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001077#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001078 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1079 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1080 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1081 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1082 _EXPORT_INT(m, SNDCTL_DSP_POST);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001083#ifdef SNDCTL_DSP_PROFILE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001084 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001085#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001086 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1087 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1088 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1089 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1090 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001091#ifdef SNDCTL_DSP_SETSPDIF
Greg Ward1e0f57d2002-11-30 23:05:26 +00001092 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
Neal Norwitzfaa7b9b2003-01-10 21:27:54 +00001093#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001094 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1095 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1096 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1097 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1098 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1099 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1100 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1101 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1102 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1103 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1104 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1105 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1106 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1107 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1108 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001109#ifdef SNDCTL_SEQ_GETTIME
Greg Ward1e0f57d2002-11-30 23:05:26 +00001110 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001111#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001112 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1113 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1114 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1115 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1116 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1117 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1118 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1119 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1120 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1121 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001122#ifdef SNDCTL_SYNTH_CONTROL
Greg Ward1e0f57d2002-11-30 23:05:26 +00001123 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001124#endif
1125#ifdef SNDCTL_SYNTH_ID
Greg Ward1e0f57d2002-11-30 23:05:26 +00001126 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001127#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001128 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1129 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001130#ifdef SNDCTL_SYNTH_REMOVESAMPLE
Greg Ward1e0f57d2002-11-30 23:05:26 +00001131 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
Neal Norwitzd156c2d2003-02-02 17:59:06 +00001132#endif
Greg Ward1e0f57d2002-11-30 23:05:26 +00001133 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1134 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1135 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1136 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1137 _EXPORT_INT(m, SNDCTL_TMR_START);
1138 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1139 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1140 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
Greg Ward04613a92002-11-30 22:47:45 +00001141}