1 /*
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.
11 * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002.
12 *
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 #define PY_SSIZE_T_CLEAN
23 #include "Python.h"
24 #include "structmember.h"
25
26 #ifdef HAVE_FCNTL_H
27 #include <fcntl.h>
28 #else
29 #define O_RDONLY 00
30 #define O_WRONLY 01
31 #endif
32
33 #include <sys/ioctl.h>
34 #ifdef __ANDROID__
35 #include <linux/soundcard.h>
36 #else
37 #include <sys/soundcard.h>
38 #endif
39
40 #ifdef __linux__
41
42 #ifndef HAVE_STDINT_H
43 typedef unsigned long uint32_t;
44 #endif
45
46 #elif defined(__FreeBSD__)
47
48 # ifndef SNDCTL_DSP_CHANNELS
49 # define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
50 # endif
51
52 #endif
53
54 typedef struct {
55 PyObject_HEAD
56 const char *devicename; /* name of the device file */
57 int fd; /* file descriptor */
58 int mode; /* file mode (O_RDONLY, etc.) */
59 Py_ssize_t icount; /* input count */
60 Py_ssize_t ocount; /* output count */
61 uint32_t afmts; /* audio formats supported by hardware */
62 } oss_audio_t;
63
64 typedef struct {
65 PyObject_HEAD
66 int fd; /* The open mixer device */
67 } oss_mixer_t;
68
69
70 static PyTypeObject OSSAudioType;
71 static PyTypeObject OSSMixerType;
72
73 static PyObject *OSSAudioError;
74
75
76 /* ----------------------------------------------------------------------
77 * DSP object initialization/deallocation
78 */
79
80 static oss_audio_t *
newossobject(PyObject * arg)81 newossobject(PyObject *arg)
82 {
83 oss_audio_t *self;
84 int fd, afmts, imode;
85 const char *devicename = NULL;
86 const char *mode = NULL;
87
88 /* Two ways to call open():
89 open(device, mode) (for consistency with builtin open())
90 open(mode) (for backwards compatibility)
91 because the *first* argument is optional, parsing args is
92 a wee bit tricky. */
93 if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode))
94 return NULL;
95 if (mode == NULL) { /* only one arg supplied */
96 mode = devicename;
97 devicename = NULL;
98 }
99
100 if (strcmp(mode, "r") == 0)
101 imode = O_RDONLY;
102 else if (strcmp(mode, "w") == 0)
103 imode = O_WRONLY;
104 else if (strcmp(mode, "rw") == 0)
105 imode = O_RDWR;
106 else {
107 PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'");
108 return NULL;
109 }
110
111 /* Open the correct device: either the 'device' argument,
112 or the AUDIODEV environment variable, or "/dev/dsp". */
113 if (devicename == NULL) { /* called with one arg */
114 devicename = getenv("AUDIODEV");
115 if (devicename == NULL) /* $AUDIODEV not set */
116 devicename = "/dev/dsp";
117 }
118
119 /* Open with O_NONBLOCK to avoid hanging on devices that only allow
120 one open at a time. This does *not* affect later I/O; OSS
121 provides a special ioctl() for non-blocking read/write, which is
122 exposed via oss_nonblock() below. */
123 fd = _Py_open(devicename, imode|O_NONBLOCK);
124 if (fd == -1)
125 return NULL;
126
127 /* And (try to) put it back in blocking mode so we get the
128 expected write() semantics. */
129 if (fcntl(fd, F_SETFL, 0) == -1) {
130 close(fd);
131 PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
132 return NULL;
133 }
134
135 if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
136 close(fd);
137 PyErr_SetFromErrnoWithFilename(PyExc_OSError, devicename);
138 return NULL;
139 }
140 /* Create and initialize the object */
141 if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) {
142 close(fd);
143 return NULL;
144 }
145 self->devicename = devicename;
146 self->fd = fd;
147 self->mode = imode;
148 self->icount = self->ocount = 0;
149 self->afmts = afmts;
150 return self;
151 }
152
153 static void
oss_dealloc(oss_audio_t * self)154 oss_dealloc(oss_audio_t *self)
155 {
156 /* if already closed, don't reclose it */
157 if (self->fd != -1)
158 close(self->fd);
159 PyObject_Del(self);
160 }
161
162
163 /* ----------------------------------------------------------------------
164 * Mixer object initialization/deallocation
165 */
166
167 static oss_mixer_t *
newossmixerobject(PyObject * arg)168 newossmixerobject(PyObject *arg)
169 {
170 const char *devicename = NULL;
171 int fd;
172 oss_mixer_t *self;
173
174 if (!PyArg_ParseTuple(arg, "|s", &devicename)) {
175 return NULL;
176 }
177
178 if (devicename == NULL) {
179 devicename = getenv("MIXERDEV");
180 if (devicename == NULL) /* MIXERDEV not set */
181 devicename = "/dev/mixer";
182 }
183
184 fd = _Py_open(devicename, O_RDWR);
185 if (fd == -1)
186 return NULL;
187
188 if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) {
189 close(fd);
190 return NULL;
191 }
192
193 self->fd = fd;
194
195 return self;
196 }
197
198 static void
oss_mixer_dealloc(oss_mixer_t * self)199 oss_mixer_dealloc(oss_mixer_t *self)
200 {
201 /* if already closed, don't reclose it */
202 if (self->fd != -1)
203 close(self->fd);
204 PyObject_Del(self);
205 }
206
207
208 /* Methods to wrap the OSS ioctls. The calling convention is pretty
209 simple:
210 nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK)
211 fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt)
212 etc.
213 */
214
215
216 /* ----------------------------------------------------------------------
217 * Helper functions
218 */
219
220 /* Check if a given file descriptor is valid (i.e. hasn't been closed).
221 * If true, return 1. Otherwise, raise ValueError and return 0.
222 */
_is_fd_valid(int fd)223 static int _is_fd_valid(int fd)
224 {
225 /* the FD is set to -1 in oss_close()/oss_mixer_close() */
226 if (fd >= 0) {
227 return 1;
228 } else {
229 PyErr_SetString(PyExc_ValueError,
230 "Operation on closed OSS device.");
231 return 0;
232 }
233 }
234
235 /* _do_ioctl_1() is a private helper function used for the OSS ioctls --
236 SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that are called from C
237 like this:
238 ioctl(fd, SNDCTL_DSP_cmd, &arg)
239
240 where arg is the value to set, and on return the driver sets arg to
241 the value that was actually set. Mapping this to Python is obvious:
242 arg = dsp.xxx(arg)
243 */
244 static PyObject *
_do_ioctl_1(int fd,PyObject * args,char * fname,unsigned long cmd)245 _do_ioctl_1(int fd, PyObject *args, char *fname, unsigned long cmd)
246 {
247 char argfmt[33] = "i:";
248 int arg;
249
250 assert(strlen(fname) <= 30);
251 strncat(argfmt, fname, 30);
252 if (!PyArg_ParseTuple(args, argfmt, &arg))
253 return NULL;
254
255 if (ioctl(fd, cmd, &arg) == -1)
256 return PyErr_SetFromErrno(PyExc_OSError);
257 return PyLong_FromLong(arg);
258 }
259
260
261 /* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs
262 but return an output -- ie. we need to pass a pointer to a local C
263 variable so the driver can write its output there, but from Python
264 all we see is the return value. For example,
265 SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer
266 devices, but does not use the value of the parameter passed-in in any
267 way.
268 */
269 static PyObject *
_do_ioctl_1_internal(int fd,PyObject * args,char * fname,unsigned long cmd)270 _do_ioctl_1_internal(int fd, PyObject *args, char *fname, unsigned long cmd)
271 {
272 char argfmt[32] = ":";
273 int arg = 0;
274
275 assert(strlen(fname) <= 30);
276 strncat(argfmt, fname, 30);
277 if (!PyArg_ParseTuple(args, argfmt, &arg))
278 return NULL;
279
280 if (ioctl(fd, cmd, &arg) == -1)
281 return PyErr_SetFromErrno(PyExc_OSError);
282 return PyLong_FromLong(arg);
283 }
284
285
286
287 /* _do_ioctl_0() is a private helper for the no-argument ioctls:
288 SNDCTL_DSP_{SYNC,RESET,POST}. */
289 static PyObject *
_do_ioctl_0(int fd,PyObject * args,char * fname,unsigned long cmd)290 _do_ioctl_0(int fd, PyObject *args, char *fname, unsigned long cmd)
291 {
292 char argfmt[32] = ":";
293 int rv;
294
295 assert(strlen(fname) <= 30);
296 strncat(argfmt, fname, 30);
297 if (!PyArg_ParseTuple(args, argfmt))
298 return NULL;
299
300 /* According to hannu@opensound.com, all three of the ioctls that
301 use this function can block, so release the GIL. This is
302 especially important for SYNC, which can block for several
303 seconds. */
304 Py_BEGIN_ALLOW_THREADS
305 rv = ioctl(fd, cmd, 0);
306 Py_END_ALLOW_THREADS
307
308 if (rv == -1)
309 return PyErr_SetFromErrno(PyExc_OSError);
310 Py_RETURN_NONE;
311 }
312
313
314 /* ----------------------------------------------------------------------
315 * Methods of DSP objects (OSSAudioType)
316 */
317
318 static PyObject *
oss_nonblock(oss_audio_t * self,PyObject * unused)319 oss_nonblock(oss_audio_t *self, PyObject *unused)
320 {
321 if (!_is_fd_valid(self->fd))
322 return NULL;
323
324 /* Hmmm: it doesn't appear to be possible to return to blocking
325 mode once we're in non-blocking mode! */
326 if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
327 return PyErr_SetFromErrno(PyExc_OSError);
328 Py_RETURN_NONE;
329 }
330
331 static PyObject *
oss_setfmt(oss_audio_t * self,PyObject * args)332 oss_setfmt(oss_audio_t *self, PyObject *args)
333 {
334 if (!_is_fd_valid(self->fd))
335 return NULL;
336
337 return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
338 }
339
340 static PyObject *
oss_getfmts(oss_audio_t * self,PyObject * unused)341 oss_getfmts(oss_audio_t *self, PyObject *unused)
342 {
343 int mask;
344
345 if (!_is_fd_valid(self->fd))
346 return NULL;
347
348 if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
349 return PyErr_SetFromErrno(PyExc_OSError);
350 return PyLong_FromLong(mask);
351 }
352
353 static PyObject *
oss_channels(oss_audio_t * self,PyObject * args)354 oss_channels(oss_audio_t *self, PyObject *args)
355 {
356 if (!_is_fd_valid(self->fd))
357 return NULL;
358
359 return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
360 }
361
362 static PyObject *
oss_speed(oss_audio_t * self,PyObject * args)363 oss_speed(oss_audio_t *self, PyObject *args)
364 {
365 if (!_is_fd_valid(self->fd))
366 return NULL;
367
368 return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
369 }
370
371 static PyObject *
oss_sync(oss_audio_t * self,PyObject * args)372 oss_sync(oss_audio_t *self, PyObject *args)
373 {
374 if (!_is_fd_valid(self->fd))
375 return NULL;
376
377 return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
378 }
379
380 static PyObject *
oss_reset(oss_audio_t * self,PyObject * args)381 oss_reset(oss_audio_t *self, PyObject *args)
382 {
383 if (!_is_fd_valid(self->fd))
384 return NULL;
385
386 return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
387 }
388
389 static PyObject *
oss_post(oss_audio_t * self,PyObject * args)390 oss_post(oss_audio_t *self, PyObject *args)
391 {
392 if (!_is_fd_valid(self->fd))
393 return NULL;
394
395 return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
396 }
397
398
399 /* Regular file methods: read(), write(), close(), etc. as well
400 as one convenience method, writeall(). */
401
402 static PyObject *
oss_read(oss_audio_t * self,PyObject * args)403 oss_read(oss_audio_t *self, PyObject *args)
404 {
405 Py_ssize_t size, count;
406 PyObject *rv;
407
408 if (!_is_fd_valid(self->fd))
409 return NULL;
410
411 if (!PyArg_ParseTuple(args, "n:read", &size))
412 return NULL;
413
414 rv = PyBytes_FromStringAndSize(NULL, size);
415 if (rv == NULL)
416 return NULL;
417
418 count = _Py_read(self->fd, PyBytes_AS_STRING(rv), size);
419 if (count == -1) {
420 Py_DECREF(rv);
421 return NULL;
422 }
423
424 self->icount += count;
425 _PyBytes_Resize(&rv, count);
426 return rv;
427 }
428
429 static PyObject *
oss_write(oss_audio_t * self,PyObject * args)430 oss_write(oss_audio_t *self, PyObject *args)
431 {
432 Py_buffer data;
433 Py_ssize_t rv;
434
435 if (!_is_fd_valid(self->fd))
436 return NULL;
437
438 if (!PyArg_ParseTuple(args, "y*:write", &data)) {
439 return NULL;
440 }
441
442 rv = _Py_write(self->fd, data.buf, data.len);
443 PyBuffer_Release(&data);
444 if (rv == -1)
445 return NULL;
446
447 self->ocount += rv;
448 return PyLong_FromLong(rv);
449 }
450
451 static PyObject *
oss_writeall(oss_audio_t * self,PyObject * args)452 oss_writeall(oss_audio_t *self, PyObject *args)
453 {
454 Py_buffer data;
455 const char *cp;
456 Py_ssize_t size;
457 Py_ssize_t rv;
458 fd_set write_set_fds;
459 int select_rv;
460
461 /* NB. writeall() is only useful in non-blocking mode: according to
462 Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
463 (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
464 write() in blocking mode consumes the whole buffer. In blocking
465 mode, the behaviour of write() and writeall() from Python is
466 indistinguishable. */
467
468 if (!_is_fd_valid(self->fd))
469 return NULL;
470
471 if (!PyArg_ParseTuple(args, "y*:writeall", &data))
472 return NULL;
473
474 if (!_PyIsSelectable_fd(self->fd)) {
475 PyErr_SetString(PyExc_ValueError,
476 "file descriptor out of range for select");
477 PyBuffer_Release(&data);
478 return NULL;
479 }
480 /* use select to wait for audio device to be available */
481 FD_ZERO(&write_set_fds);
482 FD_SET(self->fd, &write_set_fds);
483 cp = (const char *)data.buf;
484 size = data.len;
485
486 while (size > 0) {
487 Py_BEGIN_ALLOW_THREADS
488 select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
489 Py_END_ALLOW_THREADS
490
491 assert(select_rv != 0); /* no timeout, can't expire */
492 if (select_rv == -1) {
493 PyBuffer_Release(&data);
494 return PyErr_SetFromErrno(PyExc_OSError);
495 }
496
497 rv = _Py_write(self->fd, cp, Py_MIN(size, INT_MAX));
498 if (rv == -1) {
499 /* buffer is full, try again */
500 if (errno == EAGAIN) {
501 PyErr_Clear();
502 continue;
503 }
504 /* it's a real error */
505 PyBuffer_Release(&data);
506 return NULL;
507 }
508
509 /* wrote rv bytes */
510 self->ocount += rv;
511 size -= rv;
512 cp += rv;
513 }
514 PyBuffer_Release(&data);
515 Py_RETURN_NONE;
516 }
517
518 static PyObject *
oss_close(oss_audio_t * self,PyObject * unused)519 oss_close(oss_audio_t *self, PyObject *unused)
520 {
521 if (self->fd >= 0) {
522 Py_BEGIN_ALLOW_THREADS
523 close(self->fd);
524 Py_END_ALLOW_THREADS
525 self->fd = -1;
526 }
527 Py_RETURN_NONE;
528 }
529
530 static PyObject *
oss_self(PyObject * self,PyObject * unused)531 oss_self(PyObject *self, PyObject *unused)
532 {
533 Py_INCREF(self);
534 return self;
535 }
536
537 static PyObject *
oss_exit(PyObject * self,PyObject * unused)538 oss_exit(PyObject *self, PyObject *unused)
539 {
540 _Py_IDENTIFIER(close);
541
542 PyObject *ret = _PyObject_CallMethodId(self, &PyId_close, NULL);
543 if (!ret)
544 return NULL;
545 Py_DECREF(ret);
546 Py_RETURN_NONE;
547 }
548
549 static PyObject *
oss_fileno(oss_audio_t * self,PyObject * unused)550 oss_fileno(oss_audio_t *self, PyObject *unused)
551 {
552 if (!_is_fd_valid(self->fd))
553 return NULL;
554
555 return PyLong_FromLong(self->fd);
556 }
557
558
559 /* Convenience methods: these generally wrap a couple of ioctls into one
560 common task. */
561
562 static PyObject *
oss_setparameters(oss_audio_t * self,PyObject * args)563 oss_setparameters(oss_audio_t *self, PyObject *args)
564 {
565 int wanted_fmt, wanted_channels, wanted_rate, strict=0;
566 int fmt, channels, rate;
567
568 if (!_is_fd_valid(self->fd))
569 return NULL;
570
571 if (!PyArg_ParseTuple(args, "iii|i:setparameters",
572 &wanted_fmt, &wanted_channels, &wanted_rate,
573 &strict))
574 return NULL;
575
576 fmt = wanted_fmt;
577 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) {
578 return PyErr_SetFromErrno(PyExc_OSError);
579 }
580 if (strict && fmt != wanted_fmt) {
581 return PyErr_Format
582 (OSSAudioError,
583 "unable to set requested format (wanted %d, got %d)",
584 wanted_fmt, fmt);
585 }
586
587 channels = wanted_channels;
588 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) {
589 return PyErr_SetFromErrno(PyExc_OSError);
590 }
591 if (strict && channels != wanted_channels) {
592 return PyErr_Format
593 (OSSAudioError,
594 "unable to set requested channels (wanted %d, got %d)",
595 wanted_channels, channels);
596 }
597
598 rate = wanted_rate;
599 if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
600 return PyErr_SetFromErrno(PyExc_OSError);
601 }
602 if (strict && rate != wanted_rate) {
603 return PyErr_Format
604 (OSSAudioError,
605 "unable to set requested rate (wanted %d, got %d)",
606 wanted_rate, rate);
607 }
608
609 /* Construct the return value: a (fmt, channels, rate) tuple that
610 tells what the audio hardware was actually set to. */
611 return Py_BuildValue("(iii)", fmt, channels, rate);
612 }
613
614 static int
_ssize(oss_audio_t * self,int * nchannels,int * ssize)615 _ssize(oss_audio_t *self, int *nchannels, int *ssize)
616 {
617 int fmt;
618
619 fmt = 0;
620 if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
621 return -errno;
622
623 switch (fmt) {
624 case AFMT_MU_LAW:
625 case AFMT_A_LAW:
626 case AFMT_U8:
627 case AFMT_S8:
628 *ssize = 1; /* 8 bit formats: 1 byte */
629 break;
630 case AFMT_S16_LE:
631 case AFMT_S16_BE:
632 case AFMT_U16_LE:
633 case AFMT_U16_BE:
634 *ssize = 2; /* 16 bit formats: 2 byte */
635 break;
636 case AFMT_MPEG:
637 case AFMT_IMA_ADPCM:
638 default:
639 return -EOPNOTSUPP;
640 }
641 if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
642 return -errno;
643 return 0;
644 }
645
646
647 /* bufsize returns the size of the hardware audio buffer in number
648 of samples */
649 static PyObject *
oss_bufsize(oss_audio_t * self,PyObject * unused)650 oss_bufsize(oss_audio_t *self, PyObject *unused)
651 {
652 audio_buf_info ai;
653 int nchannels=0, ssize=0;
654
655 if (!_is_fd_valid(self->fd))
656 return NULL;
657
658 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
659 PyErr_SetFromErrno(PyExc_OSError);
660 return NULL;
661 }
662 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
663 PyErr_SetFromErrno(PyExc_OSError);
664 return NULL;
665 }
666 return PyLong_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
667 }
668
669 /* obufcount returns the number of samples that are available in the
670 hardware for playing */
671 static PyObject *
oss_obufcount(oss_audio_t * self,PyObject * unused)672 oss_obufcount(oss_audio_t *self, PyObject *unused)
673 {
674 audio_buf_info ai;
675 int nchannels=0, ssize=0;
676
677 if (!_is_fd_valid(self->fd))
678 return NULL;
679
680 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
681 PyErr_SetFromErrno(PyExc_OSError);
682 return NULL;
683 }
684 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
685 PyErr_SetFromErrno(PyExc_OSError);
686 return NULL;
687 }
688 return PyLong_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
689 (ssize * nchannels));
690 }
691
692 /* obufcount returns the number of samples that can be played without
693 blocking */
694 static PyObject *
oss_obuffree(oss_audio_t * self,PyObject * unused)695 oss_obuffree(oss_audio_t *self, PyObject *unused)
696 {
697 audio_buf_info ai;
698 int nchannels=0, ssize=0;
699
700 if (!_is_fd_valid(self->fd))
701 return NULL;
702
703 if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) {
704 PyErr_SetFromErrno(PyExc_OSError);
705 return NULL;
706 }
707 if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
708 PyErr_SetFromErrno(PyExc_OSError);
709 return NULL;
710 }
711 return PyLong_FromLong(ai.bytes / (ssize * nchannels));
712 }
713
714 static PyObject *
oss_getptr(oss_audio_t * self,PyObject * unused)715 oss_getptr(oss_audio_t *self, PyObject *unused)
716 {
717 count_info info;
718 int req;
719
720 if (!_is_fd_valid(self->fd))
721 return NULL;
722
723 if (self->mode == O_RDONLY)
724 req = SNDCTL_DSP_GETIPTR;
725 else
726 req = SNDCTL_DSP_GETOPTR;
727 if (ioctl(self->fd, req, &info) == -1) {
728 PyErr_SetFromErrno(PyExc_OSError);
729 return NULL;
730 }
731 return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
732 }
733
734
735 /* ----------------------------------------------------------------------
736 * Methods of mixer objects (OSSMixerType)
737 */
738
739 static PyObject *
oss_mixer_close(oss_mixer_t * self,PyObject * unused)740 oss_mixer_close(oss_mixer_t *self, PyObject *unused)
741 {
742 if (self->fd >= 0) {
743 close(self->fd);
744 self->fd = -1;
745 }
746 Py_RETURN_NONE;
747 }
748
749 static PyObject *
oss_mixer_fileno(oss_mixer_t * self,PyObject * unused)750 oss_mixer_fileno(oss_mixer_t *self, PyObject *unused)
751 {
752 if (!_is_fd_valid(self->fd))
753 return NULL;
754
755 return PyLong_FromLong(self->fd);
756 }
757
758 /* Simple mixer interface methods */
759
760 static PyObject *
oss_mixer_controls(oss_mixer_t * self,PyObject * args)761 oss_mixer_controls(oss_mixer_t *self, PyObject *args)
762 {
763 if (!_is_fd_valid(self->fd))
764 return NULL;
765
766 return _do_ioctl_1_internal(self->fd, args, "controls",
767 SOUND_MIXER_READ_DEVMASK);
768 }
769
770 static PyObject *
oss_mixer_stereocontrols(oss_mixer_t * self,PyObject * args)771 oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args)
772 {
773 if (!_is_fd_valid(self->fd))
774 return NULL;
775
776 return _do_ioctl_1_internal(self->fd, args, "stereocontrols",
777 SOUND_MIXER_READ_STEREODEVS);
778 }
779
780 static PyObject *
oss_mixer_reccontrols(oss_mixer_t * self,PyObject * args)781 oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args)
782 {
783 if (!_is_fd_valid(self->fd))
784 return NULL;
785
786 return _do_ioctl_1_internal(self->fd, args, "reccontrols",
787 SOUND_MIXER_READ_RECMASK);
788 }
789
790 static PyObject *
oss_mixer_get(oss_mixer_t * self,PyObject * args)791 oss_mixer_get(oss_mixer_t *self, PyObject *args)
792 {
793 int channel, volume;
794
795 if (!_is_fd_valid(self->fd))
796 return NULL;
797
798 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
799 if (!PyArg_ParseTuple(args, "i:get", &channel))
800 return NULL;
801
802 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
803 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
804 return NULL;
805 }
806
807 if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
808 return PyErr_SetFromErrno(PyExc_OSError);
809
810 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
811 }
812
813 static PyObject *
oss_mixer_set(oss_mixer_t * self,PyObject * args)814 oss_mixer_set(oss_mixer_t *self, PyObject *args)
815 {
816 int channel, volume, leftVol, rightVol;
817
818 if (!_is_fd_valid(self->fd))
819 return NULL;
820
821 /* Can't use _do_ioctl_1 because of encoded arg thingy. */
822 if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
823 return NULL;
824
825 if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
826 PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
827 return NULL;
828 }
829
830 if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
831 PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
832 return NULL;
833 }
834
835 volume = (rightVol << 8) | leftVol;
836
837 if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
838 return PyErr_SetFromErrno(PyExc_OSError);
839
840 return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
841 }
842
843 static PyObject *
oss_mixer_get_recsrc(oss_mixer_t * self,PyObject * args)844 oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args)
845 {
846 if (!_is_fd_valid(self->fd))
847 return NULL;
848
849 return _do_ioctl_1_internal(self->fd, args, "get_recsrc",
850 SOUND_MIXER_READ_RECSRC);
851 }
852
853 static PyObject *
oss_mixer_set_recsrc(oss_mixer_t * self,PyObject * args)854 oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args)
855 {
856 if (!_is_fd_valid(self->fd))
857 return NULL;
858
859 return _do_ioctl_1(self->fd, args, "set_recsrc",
860 SOUND_MIXER_WRITE_RECSRC);
861 }
862
863
864 /* ----------------------------------------------------------------------
865 * Method tables and other bureaucracy
866 */
867
868 static PyMethodDef oss_methods[] = {
869 /* Regular file methods */
870 { "read", (PyCFunction)oss_read, METH_VARARGS },
871 { "write", (PyCFunction)oss_write, METH_VARARGS },
872 { "writeall", (PyCFunction)oss_writeall, METH_VARARGS },
873 { "close", (PyCFunction)oss_close, METH_NOARGS },
874 { "fileno", (PyCFunction)oss_fileno, METH_NOARGS },
875
876 /* Simple ioctl wrappers */
877 { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS },
878 { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS },
879 { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS },
880 { "channels", (PyCFunction)oss_channels, METH_VARARGS },
881 { "speed", (PyCFunction)oss_speed, METH_VARARGS },
882 { "sync", (PyCFunction)oss_sync, METH_VARARGS },
883 { "reset", (PyCFunction)oss_reset, METH_VARARGS },
884 { "post", (PyCFunction)oss_post, METH_VARARGS },
885
886 /* Convenience methods -- wrap a couple of ioctls together */
887 { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS },
888 { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS },
889 { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS },
890 { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS },
891 { "getptr", (PyCFunction)oss_getptr, METH_NOARGS },
892
893 /* Aliases for backwards compatibility */
894 { "flush", (PyCFunction)oss_sync, METH_VARARGS },
895
896 /* Support for the context management protocol */
897 { "__enter__", oss_self, METH_NOARGS },
898 { "__exit__", oss_exit, METH_VARARGS },
899
900 { NULL, NULL} /* sentinel */
901 };
902
903 static PyMethodDef oss_mixer_methods[] = {
904 /* Regular file method - OSS mixers are ioctl-only interface */
905 { "close", (PyCFunction)oss_mixer_close, METH_NOARGS },
906 { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS },
907
908 /* Support for the context management protocol */
909 { "__enter__", oss_self, METH_NOARGS },
910 { "__exit__", oss_exit, METH_VARARGS },
911
912 /* Simple ioctl wrappers */
913 { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
914 { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
915 { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
916 { "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
917 { "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
918 { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
919 { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
920
921 { NULL, NULL}
922 };
923
924 static PyObject *
oss_getattro(oss_audio_t * self,PyObject * nameobj)925 oss_getattro(oss_audio_t *self, PyObject *nameobj)
926 {
927 const char *name = "";
928 PyObject * rval = NULL;
929
930 if (PyUnicode_Check(nameobj)) {
931 name = PyUnicode_AsUTF8(nameobj);
932 if (name == NULL)
933 return NULL;
934 }
935
936 if (strcmp(name, "closed") == 0) {
937 rval = (self->fd == -1) ? Py_True : Py_False;
938 Py_INCREF(rval);
939 }
940 else if (strcmp(name, "name") == 0) {
941 rval = PyUnicode_FromString(self->devicename);
942 }
943 else if (strcmp(name, "mode") == 0) {
944 /* No need for a "default" in this switch: from newossobject(),
945 self->mode can only be one of these three values. */
946 switch(self->mode) {
947 case O_RDONLY:
948 rval = PyUnicode_FromString("r");
949 break;
950 case O_RDWR:
951 rval = PyUnicode_FromString("rw");
952 break;
953 case O_WRONLY:
954 rval = PyUnicode_FromString("w");
955 break;
956 }
957 }
958 else {
959 rval = PyObject_GenericGetAttr((PyObject *)self, nameobj);
960 }
961 return rval;
962 }
963
964 static PyTypeObject OSSAudioType = {
965 PyVarObject_HEAD_INIT(&PyType_Type, 0)
966 "ossaudiodev.oss_audio_device", /*tp_name*/
967 sizeof(oss_audio_t), /*tp_basicsize*/
968 0, /*tp_itemsize*/
969 /* methods */
970 (destructor)oss_dealloc, /*tp_dealloc*/
971 0, /*tp_print*/
972 0, /*tp_getattr*/
973 0, /*tp_setattr*/
974 0, /*tp_reserved*/
975 0, /*tp_repr*/
976 0, /*tp_as_number*/
977 0, /*tp_as_sequence*/
978 0, /*tp_as_mapping*/
979 0, /*tp_hash*/
980 0, /*tp_call*/
981 0, /*tp_str*/
982 (getattrofunc)oss_getattro, /*tp_getattro*/
983 0, /*tp_setattro*/
984 0, /*tp_as_buffer*/
985 Py_TPFLAGS_DEFAULT, /*tp_flags*/
986 0, /*tp_doc*/
987 0, /*tp_traverse*/
988 0, /*tp_clear*/
989 0, /*tp_richcompare*/
990 0, /*tp_weaklistoffset*/
991 0, /*tp_iter*/
992 0, /*tp_iternext*/
993 oss_methods, /*tp_methods*/
994 };
995
996 static PyTypeObject OSSMixerType = {
997 PyVarObject_HEAD_INIT(&PyType_Type, 0)
998 "ossaudiodev.oss_mixer_device", /*tp_name*/
999 sizeof(oss_mixer_t), /*tp_basicsize*/
1000 0, /*tp_itemsize*/
1001 /* methods */
1002 (destructor)oss_mixer_dealloc, /*tp_dealloc*/
1003 0, /*tp_print*/
1004 0, /*tp_getattr*/
1005 0, /*tp_setattr*/
1006 0, /*tp_reserved*/
1007 0, /*tp_repr*/
1008 0, /*tp_as_number*/
1009 0, /*tp_as_sequence*/
1010 0, /*tp_as_mapping*/
1011 0, /*tp_hash*/
1012 0, /*tp_call*/
1013 0, /*tp_str*/
1014 0, /*tp_getattro*/
1015 0, /*tp_setattro*/
1016 0, /*tp_as_buffer*/
1017 Py_TPFLAGS_DEFAULT, /*tp_flags*/
1018 0, /*tp_doc*/
1019 0, /*tp_traverse*/
1020 0, /*tp_clear*/
1021 0, /*tp_richcompare*/
1022 0, /*tp_weaklistoffset*/
1023 0, /*tp_iter*/
1024 0, /*tp_iternext*/
1025 oss_mixer_methods, /*tp_methods*/
1026 };
1027
1028
1029 static PyObject *
ossopen(PyObject * self,PyObject * args)1030 ossopen(PyObject *self, PyObject *args)
1031 {
1032 return (PyObject *)newossobject(args);
1033 }
1034
1035 static PyObject *
ossopenmixer(PyObject * self,PyObject * args)1036 ossopenmixer(PyObject *self, PyObject *args)
1037 {
1038 return (PyObject *)newossmixerobject(args);
1039 }
1040
1041 static PyMethodDef ossaudiodev_methods[] = {
1042 { "open", ossopen, METH_VARARGS },
1043 { "openmixer", ossopenmixer, METH_VARARGS },
1044 { 0, 0 },
1045 };
1046
1047
1048 #define _EXPORT_INT(mod, name) \
1049 if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return NULL;
1050
1051
1052 static char *control_labels[] = SOUND_DEVICE_LABELS;
1053 static char *control_names[] = SOUND_DEVICE_NAMES;
1054
1055
1056 static int
build_namelists(PyObject * module)1057 build_namelists (PyObject *module)
1058 {
1059 PyObject *labels;
1060 PyObject *names;
1061 PyObject *s;
1062 int num_controls;
1063 int i;
1064
1065 num_controls = Py_ARRAY_LENGTH(control_labels);
1066 assert(num_controls == Py_ARRAY_LENGTH(control_names));
1067
1068 labels = PyList_New(num_controls);
1069 names = PyList_New(num_controls);
1070 if (labels == NULL || names == NULL)
1071 goto error2;
1072 for (i = 0; i < num_controls; i++) {
1073 s = PyUnicode_FromString(control_labels[i]);
1074 if (s == NULL)
1075 goto error2;
1076 PyList_SET_ITEM(labels, i, s);
1077
1078 s = PyUnicode_FromString(control_names[i]);
1079 if (s == NULL)
1080 goto error2;
1081 PyList_SET_ITEM(names, i, s);
1082 }
1083
1084 if (PyModule_AddObject(module, "control_labels", labels) == -1)
1085 goto error2;
1086 if (PyModule_AddObject(module, "control_names", names) == -1)
1087 goto error1;
1088
1089 return 0;
1090
1091 error2:
1092 Py_XDECREF(labels);
1093 error1:
1094 Py_XDECREF(names);
1095 return -1;
1096 }
1097
1098
1099 static struct PyModuleDef ossaudiodevmodule = {
1100 PyModuleDef_HEAD_INIT,
1101 "ossaudiodev",
1102 NULL,
1103 -1,
1104 ossaudiodev_methods,
1105 NULL,
1106 NULL,
1107 NULL,
1108 NULL
1109 };
1110
1111 PyMODINIT_FUNC
PyInit_ossaudiodev(void)1112 PyInit_ossaudiodev(void)
1113 {
1114 PyObject *m;
1115
1116 if (PyType_Ready(&OSSAudioType) < 0)
1117 return NULL;
1118
1119 if (PyType_Ready(&OSSMixerType) < 0)
1120 return NULL;
1121
1122 m = PyModule_Create(&ossaudiodevmodule);
1123 if (m == NULL)
1124 return NULL;
1125
1126 OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
1127 NULL, NULL);
1128 if (OSSAudioError) {
1129 /* Each call to PyModule_AddObject decrefs it; compensate: */
1130 Py_INCREF(OSSAudioError);
1131 Py_INCREF(OSSAudioError);
1132 PyModule_AddObject(m, "error", OSSAudioError);
1133 PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
1134 }
1135
1136 /* Build 'control_labels' and 'control_names' lists and add them
1137 to the module. */
1138 if (build_namelists(m) == -1) /* XXX what to do here? */
1139 return NULL;
1140
1141 /* Expose the audio format numbers -- essential! */
1142 _EXPORT_INT(m, AFMT_QUERY);
1143 _EXPORT_INT(m, AFMT_MU_LAW);
1144 _EXPORT_INT(m, AFMT_A_LAW);
1145 _EXPORT_INT(m, AFMT_IMA_ADPCM);
1146 _EXPORT_INT(m, AFMT_U8);
1147 _EXPORT_INT(m, AFMT_S16_LE);
1148 _EXPORT_INT(m, AFMT_S16_BE);
1149 _EXPORT_INT(m, AFMT_S8);
1150 _EXPORT_INT(m, AFMT_U16_LE);
1151 _EXPORT_INT(m, AFMT_U16_BE);
1152 _EXPORT_INT(m, AFMT_MPEG);
1153 #ifdef AFMT_AC3
1154 _EXPORT_INT(m, AFMT_AC3);
1155 #endif
1156 #ifdef AFMT_S16_NE
1157 _EXPORT_INT(m, AFMT_S16_NE);
1158 #endif
1159 #ifdef AFMT_U16_NE
1160 _EXPORT_INT(m, AFMT_U16_NE);
1161 #endif
1162 #ifdef AFMT_S32_LE
1163 _EXPORT_INT(m, AFMT_S32_LE);
1164 #endif
1165 #ifdef AFMT_S32_BE
1166 _EXPORT_INT(m, AFMT_S32_BE);
1167 #endif
1168 #ifdef AFMT_MPEG
1169 _EXPORT_INT(m, AFMT_MPEG);
1170 #endif
1171
1172 /* Expose the sound mixer device numbers. */
1173 _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
1174 _EXPORT_INT(m, SOUND_MIXER_VOLUME);
1175 _EXPORT_INT(m, SOUND_MIXER_BASS);
1176 _EXPORT_INT(m, SOUND_MIXER_TREBLE);
1177 _EXPORT_INT(m, SOUND_MIXER_SYNTH);
1178 _EXPORT_INT(m, SOUND_MIXER_PCM);
1179 _EXPORT_INT(m, SOUND_MIXER_SPEAKER);
1180 _EXPORT_INT(m, SOUND_MIXER_LINE);
1181 _EXPORT_INT(m, SOUND_MIXER_MIC);
1182 _EXPORT_INT(m, SOUND_MIXER_CD);
1183 _EXPORT_INT(m, SOUND_MIXER_IMIX);
1184 _EXPORT_INT(m, SOUND_MIXER_ALTPCM);
1185 _EXPORT_INT(m, SOUND_MIXER_RECLEV);
1186 _EXPORT_INT(m, SOUND_MIXER_IGAIN);
1187 _EXPORT_INT(m, SOUND_MIXER_OGAIN);
1188 _EXPORT_INT(m, SOUND_MIXER_LINE1);
1189 _EXPORT_INT(m, SOUND_MIXER_LINE2);
1190 _EXPORT_INT(m, SOUND_MIXER_LINE3);
1191 #ifdef SOUND_MIXER_DIGITAL1
1192 _EXPORT_INT(m, SOUND_MIXER_DIGITAL1);
1193 #endif
1194 #ifdef SOUND_MIXER_DIGITAL2
1195 _EXPORT_INT(m, SOUND_MIXER_DIGITAL2);
1196 #endif
1197 #ifdef SOUND_MIXER_DIGITAL3
1198 _EXPORT_INT(m, SOUND_MIXER_DIGITAL3);
1199 #endif
1200 #ifdef SOUND_MIXER_PHONEIN
1201 _EXPORT_INT(m, SOUND_MIXER_PHONEIN);
1202 #endif
1203 #ifdef SOUND_MIXER_PHONEOUT
1204 _EXPORT_INT(m, SOUND_MIXER_PHONEOUT);
1205 #endif
1206 #ifdef SOUND_MIXER_VIDEO
1207 _EXPORT_INT(m, SOUND_MIXER_VIDEO);
1208 #endif
1209 #ifdef SOUND_MIXER_RADIO
1210 _EXPORT_INT(m, SOUND_MIXER_RADIO);
1211 #endif
1212 #ifdef SOUND_MIXER_MONITOR
1213 _EXPORT_INT(m, SOUND_MIXER_MONITOR);
1214 #endif
1215
1216 /* Expose all the ioctl numbers for masochists who like to do this
1217 stuff directly. */
1218 #ifdef SNDCTL_COPR_HALT
1219 _EXPORT_INT(m, SNDCTL_COPR_HALT);
1220 #endif
1221 #ifdef SNDCTL_COPR_LOAD
1222 _EXPORT_INT(m, SNDCTL_COPR_LOAD);
1223 #endif
1224 #ifdef SNDCTL_COPR_RCODE
1225 _EXPORT_INT(m, SNDCTL_COPR_RCODE);
1226 #endif
1227 #ifdef SNDCTL_COPR_RCVMSG
1228 _EXPORT_INT(m, SNDCTL_COPR_RCVMSG);
1229 #endif
1230 #ifdef SNDCTL_COPR_RDATA
1231 _EXPORT_INT(m, SNDCTL_COPR_RDATA);
1232 #endif
1233 #ifdef SNDCTL_COPR_RESET
1234 _EXPORT_INT(m, SNDCTL_COPR_RESET);
1235 #endif
1236 #ifdef SNDCTL_COPR_RUN
1237 _EXPORT_INT(m, SNDCTL_COPR_RUN);
1238 #endif
1239 #ifdef SNDCTL_COPR_SENDMSG
1240 _EXPORT_INT(m, SNDCTL_COPR_SENDMSG);
1241 #endif
1242 #ifdef SNDCTL_COPR_WCODE
1243 _EXPORT_INT(m, SNDCTL_COPR_WCODE);
1244 #endif
1245 #ifdef SNDCTL_COPR_WDATA
1246 _EXPORT_INT(m, SNDCTL_COPR_WDATA);
1247 #endif
1248 #ifdef SNDCTL_DSP_BIND_CHANNEL
1249 _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL);
1250 #endif
1251 _EXPORT_INT(m, SNDCTL_DSP_CHANNELS);
1252 _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE);
1253 _EXPORT_INT(m, SNDCTL_DSP_GETCAPS);
1254 #ifdef SNDCTL_DSP_GETCHANNELMASK
1255 _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK);
1256 #endif
1257 _EXPORT_INT(m, SNDCTL_DSP_GETFMTS);
1258 _EXPORT_INT(m, SNDCTL_DSP_GETIPTR);
1259 _EXPORT_INT(m, SNDCTL_DSP_GETISPACE);
1260 #ifdef SNDCTL_DSP_GETODELAY
1261 _EXPORT_INT(m, SNDCTL_DSP_GETODELAY);
1262 #endif
1263 _EXPORT_INT(m, SNDCTL_DSP_GETOPTR);
1264 _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE);
1265 #ifdef SNDCTL_DSP_GETSPDIF
1266 _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF);
1267 #endif
1268 _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER);
1269 _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF);
1270 _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF);
1271 _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK);
1272 _EXPORT_INT(m, SNDCTL_DSP_POST);
1273 #ifdef SNDCTL_DSP_PROFILE
1274 _EXPORT_INT(m, SNDCTL_DSP_PROFILE);
1275 #endif
1276 _EXPORT_INT(m, SNDCTL_DSP_RESET);
1277 _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE);
1278 _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX);
1279 _EXPORT_INT(m, SNDCTL_DSP_SETFMT);
1280 _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT);
1281 #ifdef SNDCTL_DSP_SETSPDIF
1282 _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF);
1283 #endif
1284 _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO);
1285 _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER);
1286 _EXPORT_INT(m, SNDCTL_DSP_SPEED);
1287 _EXPORT_INT(m, SNDCTL_DSP_STEREO);
1288 _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE);
1289 _EXPORT_INT(m, SNDCTL_DSP_SYNC);
1290 _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE);
1291 _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR);
1292 _EXPORT_INT(m, SNDCTL_MIDI_INFO);
1293 #ifdef SNDCTL_MIDI_MPUCMD
1294 _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD);
1295 #endif
1296 #ifdef SNDCTL_MIDI_MPUMODE
1297 _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE);
1298 #endif
1299 _EXPORT_INT(m, SNDCTL_MIDI_PRETIME);
1300 _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE);
1301 _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT);
1302 _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT);
1303 #ifdef SNDCTL_SEQ_GETTIME
1304 _EXPORT_INT(m, SNDCTL_SEQ_GETTIME);
1305 #endif
1306 _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS);
1307 _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS);
1308 _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND);
1309 _EXPORT_INT(m, SNDCTL_SEQ_PANIC);
1310 _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE);
1311 _EXPORT_INT(m, SNDCTL_SEQ_RESET);
1312 _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES);
1313 _EXPORT_INT(m, SNDCTL_SEQ_SYNC);
1314 _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI);
1315 _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD);
1316 #ifdef SNDCTL_SYNTH_CONTROL
1317 _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL);
1318 #endif
1319 #ifdef SNDCTL_SYNTH_ID
1320 _EXPORT_INT(m, SNDCTL_SYNTH_ID);
1321 #endif
1322 _EXPORT_INT(m, SNDCTL_SYNTH_INFO);
1323 _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL);
1324 #ifdef SNDCTL_SYNTH_REMOVESAMPLE
1325 _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE);
1326 #endif
1327 _EXPORT_INT(m, SNDCTL_TMR_CONTINUE);
1328 _EXPORT_INT(m, SNDCTL_TMR_METRONOME);
1329 _EXPORT_INT(m, SNDCTL_TMR_SELECT);
1330 _EXPORT_INT(m, SNDCTL_TMR_SOURCE);
1331 _EXPORT_INT(m, SNDCTL_TMR_START);
1332 _EXPORT_INT(m, SNDCTL_TMR_STOP);
1333 _EXPORT_INT(m, SNDCTL_TMR_TEMPO);
1334 _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE);
1335 return m;
1336 }
1337