Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 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. |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 11 | * Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002. |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 12 | * |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 13 | * (c) 2000 Peter Bosch. All Rights Reserved. |
| 14 | * (c) 2002 Gregory P. Ward. All Rights Reserved. |
| 15 | * (c) 2002 Python Software Foundation. All Rights Reserved. |
| 16 | * |
| 17 | * XXX need a license statement |
| 18 | * |
| 19 | * $Id$ |
| 20 | */ |
| 21 | |
| 22 | #include "Python.h" |
| 23 | #include "structmember.h" |
| 24 | |
| 25 | #ifdef HAVE_FCNTL_H |
| 26 | #include <fcntl.h> |
| 27 | #else |
| 28 | #define O_RDONLY 00 |
| 29 | #define O_WRONLY 01 |
| 30 | #endif |
| 31 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 32 | #include <sys/ioctl.h> |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 33 | #include <sys/soundcard.h> |
| 34 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 35 | #if defined(linux) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 36 | |
Armin Rigo | 0d2f498 | 2006-10-04 10:23:57 +0000 | [diff] [blame] | 37 | #ifndef HAVE_STDINT_H |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 38 | typedef unsigned long uint32_t; |
Armin Rigo | 0d2f498 | 2006-10-04 10:23:57 +0000 | [diff] [blame] | 39 | #endif |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 40 | |
| 41 | #elif defined(__FreeBSD__) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 42 | |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 43 | # ifndef SNDCTL_DSP_CHANNELS |
| 44 | # define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS |
| 45 | # endif |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 46 | |
| 47 | #endif |
| 48 | |
| 49 | typedef struct { |
Neal Norwitz | 3f04648 | 2006-01-07 21:19:49 +0000 | [diff] [blame] | 50 | PyObject_HEAD |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 51 | 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 Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 57 | } oss_audio_t; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 58 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 59 | typedef struct { |
Neal Norwitz | 3f04648 | 2006-01-07 21:19:49 +0000 | [diff] [blame] | 60 | PyObject_HEAD |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 61 | int fd; /* The open mixer device */ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 62 | } oss_mixer_t; |
| 63 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 64 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 65 | static PyTypeObject OSSAudioType; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 66 | static PyTypeObject OSSMixerType; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 67 | |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 68 | static PyObject *OSSAudioError; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 69 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 70 | |
| 71 | /* ---------------------------------------------------------------------- |
| 72 | * DSP object initialization/deallocation |
| 73 | */ |
| 74 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 75 | static oss_audio_t * |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 76 | newossobject(PyObject *arg) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 77 | { |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 78 | oss_audio_t *self; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 79 | int fd, afmts, imode; |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 80 | char *devicename = NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 81 | char *mode = NULL; |
| 82 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 83 | /* Two ways to call open(): |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 84 | 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 Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 88 | if (!PyArg_ParseTuple(arg, "s|s:open", &devicename, &mode)) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 89 | return NULL; |
| 90 | if (mode == NULL) { /* only one arg supplied */ |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 91 | mode = devicename; |
| 92 | devicename = NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | if (strcmp(mode, "r") == 0) |
| 96 | imode = O_RDONLY; |
| 97 | else if (strcmp(mode, "w") == 0) |
| 98 | imode = O_WRONLY; |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 99 | else if (strcmp(mode, "rw") == 0) |
| 100 | imode = O_RDWR; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 101 | else { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 102 | PyErr_SetString(OSSAudioError, "mode must be 'r', 'w', or 'rw'"); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 103 | return NULL; |
| 104 | } |
| 105 | |
Greg Ward | 5c5c577 | 2002-12-30 02:58:04 +0000 | [diff] [blame] | 106 | /* Open the correct device: either the 'device' argument, |
| 107 | or the AUDIODEV environment variable, or "/dev/dsp". */ |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 108 | if (devicename == NULL) { /* called with one arg */ |
| 109 | devicename = getenv("AUDIODEV"); |
| 110 | if (devicename == NULL) /* $AUDIODEV not set */ |
| 111 | devicename = "/dev/dsp"; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Greg Ward | 5c49ef2 | 2003-03-11 16:53:13 +0000 | [diff] [blame] | 114 | /* 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 Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 118 | if ((fd = open(devicename, imode|O_NONBLOCK)) == -1) { |
| 119 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 120 | return NULL; |
| 121 | } |
Greg Ward | 76ffb19 | 2003-04-04 01:47:42 +0000 | [diff] [blame] | 122 | |
| 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 Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 127 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
Greg Ward | 76ffb19 | 2003-04-04 01:47:42 +0000 | [diff] [blame] | 128 | return NULL; |
| 129 | } |
| 130 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 131 | if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) { |
Charles-François Natali | 564f890 | 2011-09-29 19:43:01 +0200 | [diff] [blame] | 132 | close(fd); |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 133 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 134 | return NULL; |
| 135 | } |
| 136 | /* Create and initialize the object */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 137 | if ((self = PyObject_New(oss_audio_t, &OSSAudioType)) == NULL) { |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 138 | close(fd); |
| 139 | return NULL; |
| 140 | } |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 141 | self->devicename = devicename; |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 142 | self->fd = fd; |
| 143 | self->mode = imode; |
| 144 | self->icount = self->ocount = 0; |
| 145 | self->afmts = afmts; |
| 146 | return self; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 150 | oss_dealloc(oss_audio_t *self) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 151 | { |
| 152 | /* if already closed, don't reclose it */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 153 | if (self->fd != -1) |
| 154 | close(self->fd); |
| 155 | PyObject_Del(self); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 158 | |
| 159 | /* ---------------------------------------------------------------------- |
| 160 | * Mixer object initialization/deallocation |
| 161 | */ |
| 162 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 163 | static oss_mixer_t * |
| 164 | newossmixerobject(PyObject *arg) |
| 165 | { |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 166 | char *devicename = NULL; |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 167 | int fd; |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 168 | oss_mixer_t *self; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 169 | |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 170 | if (!PyArg_ParseTuple(arg, "|s", &devicename)) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 171 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 172 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 173 | |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 174 | if (devicename == NULL) { |
| 175 | devicename = getenv("MIXERDEV"); |
| 176 | if (devicename == NULL) /* MIXERDEV not set */ |
| 177 | devicename = "/dev/mixer"; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 180 | if ((fd = open(devicename, O_RDWR)) == -1) { |
| 181 | PyErr_SetFromErrnoWithFilename(PyExc_IOError, devicename); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 182 | return NULL; |
| 183 | } |
Greg Ward | 0b6dfb8 | 2003-03-10 03:17:06 +0000 | [diff] [blame] | 184 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 185 | if ((self = PyObject_New(oss_mixer_t, &OSSMixerType)) == NULL) { |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 186 | close(fd); |
| 187 | return NULL; |
| 188 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 189 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 190 | self->fd = fd; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 191 | |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 192 | return self; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static void |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 196 | oss_mixer_dealloc(oss_mixer_t *self) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 197 | { |
| 198 | /* if already closed, don't reclose it */ |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 199 | if (self->fd != -1) |
| 200 | close(self->fd); |
| 201 | PyObject_Del(self); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 204 | |
| 205 | /* Methods to wrap the OSS ioctls. The calling convention is pretty |
| 206 | simple: |
| 207 | nonblock() -> ioctl(fd, SNDCTL_DSP_NONBLOCK) |
| 208 | fmt = setfmt(fmt) -> ioctl(fd, SNDCTL_DSP_SETFMT, &fmt) |
| 209 | etc. |
| 210 | */ |
| 211 | |
| 212 | |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 213 | /* ---------------------------------------------------------------------- |
| 214 | * Helper functions |
| 215 | */ |
| 216 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 217 | /* _do_ioctl_1() is a private helper function used for the OSS ioctls -- |
Terry Jan Reedy | ce9cc49 | 2013-03-11 17:41:44 -0400 | [diff] [blame] | 218 | SNDCTL_DSP_{SETFMT,CHANNELS,SPEED} -- that are called from C |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 219 | like this: |
| 220 | ioctl(fd, SNDCTL_DSP_cmd, &arg) |
| 221 | |
| 222 | where arg is the value to set, and on return the driver sets arg to |
| 223 | the value that was actually set. Mapping this to Python is obvious: |
| 224 | arg = dsp.xxx(arg) |
| 225 | */ |
| 226 | static PyObject * |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 227 | _do_ioctl_1(int fd, PyObject *args, char *fname, int cmd) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 228 | { |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 229 | char argfmt[33] = "i:"; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 230 | int arg; |
| 231 | |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 232 | assert(strlen(fname) <= 30); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 233 | strcat(argfmt, fname); |
| 234 | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 235 | return NULL; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 236 | |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 237 | if (ioctl(fd, cmd, &arg) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 238 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 239 | return PyInt_FromLong(arg); |
| 240 | } |
| 241 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 242 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 243 | /* _do_ioctl_1_internal() is a wrapper for ioctls that take no inputs |
| 244 | but return an output -- ie. we need to pass a pointer to a local C |
| 245 | variable so the driver can write its output there, but from Python |
| 246 | all we see is the return value. For example, |
| 247 | SOUND_MIXER_READ_DEVMASK returns a bitmask of available mixer |
| 248 | devices, but does not use the value of the parameter passed-in in any |
| 249 | way. |
| 250 | */ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 251 | static PyObject * |
| 252 | _do_ioctl_1_internal(int fd, PyObject *args, char *fname, int cmd) |
| 253 | { |
| 254 | char argfmt[32] = ":"; |
| 255 | int arg = 0; |
| 256 | |
| 257 | assert(strlen(fname) <= 30); |
| 258 | strcat(argfmt, fname); |
| 259 | if (!PyArg_ParseTuple(args, argfmt, &arg)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 260 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 261 | |
| 262 | if (ioctl(fd, cmd, &arg) == -1) |
| 263 | return PyErr_SetFromErrno(PyExc_IOError); |
| 264 | return PyInt_FromLong(arg); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 269 | /* _do_ioctl_0() is a private helper for the no-argument ioctls: |
| 270 | SNDCTL_DSP_{SYNC,RESET,POST}. */ |
| 271 | static PyObject * |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 272 | _do_ioctl_0(int fd, PyObject *args, char *fname, int cmd) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 273 | { |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 274 | char argfmt[32] = ":"; |
Greg Ward | d0d592f | 2003-05-27 01:57:21 +0000 | [diff] [blame] | 275 | int rv; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 276 | |
Greg Ward | da9f853 | 2002-12-11 14:49:59 +0000 | [diff] [blame] | 277 | assert(strlen(fname) <= 30); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 278 | strcat(argfmt, fname); |
| 279 | if (!PyArg_ParseTuple(args, argfmt)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 280 | return NULL; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 281 | |
Greg Ward | d0d592f | 2003-05-27 01:57:21 +0000 | [diff] [blame] | 282 | /* According to hannu@opensound.com, all three of the ioctls that |
| 283 | use this function can block, so release the GIL. This is |
| 284 | especially important for SYNC, which can block for several |
| 285 | seconds. */ |
| 286 | Py_BEGIN_ALLOW_THREADS |
| 287 | rv = ioctl(fd, cmd, 0); |
| 288 | Py_END_ALLOW_THREADS |
| 289 | |
| 290 | if (rv == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 291 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 292 | Py_INCREF(Py_None); |
| 293 | return Py_None; |
| 294 | } |
| 295 | |
| 296 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 297 | /* ---------------------------------------------------------------------- |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 298 | * Methods of DSP objects (OSSAudioType) |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 299 | */ |
| 300 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 301 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 302 | oss_nonblock(oss_audio_t *self, PyObject *unused) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 303 | { |
| 304 | /* Hmmm: it doesn't appear to be possible to return to blocking |
| 305 | mode once we're in non-blocking mode! */ |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 306 | if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 307 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 308 | Py_INCREF(Py_None); |
| 309 | return Py_None; |
| 310 | } |
| 311 | |
| 312 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 313 | oss_setfmt(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 314 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 315 | return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 319 | oss_getfmts(oss_audio_t *self, PyObject *unused) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 320 | { |
| 321 | int mask; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 322 | if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 323 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 324 | return PyInt_FromLong(mask); |
| 325 | } |
| 326 | |
| 327 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 328 | oss_channels(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 329 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 330 | return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 334 | oss_speed(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 335 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 336 | return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 340 | oss_sync(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 341 | { |
Greg Ward | d0d592f | 2003-05-27 01:57:21 +0000 | [diff] [blame] | 342 | return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 343 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 344 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 345 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 346 | oss_reset(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 347 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 348 | return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 349 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 350 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 351 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 352 | oss_post(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 353 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 354 | return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
| 358 | /* Regular file methods: read(), write(), close(), etc. as well |
| 359 | as one convenience method, writeall(). */ |
| 360 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 361 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 362 | oss_read(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 363 | { |
| 364 | int size, count; |
| 365 | char *cp; |
| 366 | PyObject *rv; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 367 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 368 | if (!PyArg_ParseTuple(args, "i:read", &size)) |
| 369 | return NULL; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 370 | rv = PyString_FromStringAndSize(NULL, size); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 371 | if (rv == NULL) |
| 372 | return NULL; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 373 | cp = PyString_AS_STRING(rv); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 374 | |
| 375 | Py_BEGIN_ALLOW_THREADS |
| 376 | count = read(self->fd, cp, size); |
| 377 | Py_END_ALLOW_THREADS |
| 378 | |
| 379 | if (count < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 380 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 381 | Py_DECREF(rv); |
| 382 | return NULL; |
| 383 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 384 | self->icount += count; |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 385 | _PyString_Resize(&rv, count); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 386 | return rv; |
| 387 | } |
| 388 | |
| 389 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 390 | oss_write(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 391 | { |
| 392 | char *cp; |
| 393 | int rv, size; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 394 | |
| 395 | if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 396 | return NULL; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 397 | } |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 398 | |
| 399 | Py_BEGIN_ALLOW_THREADS |
| 400 | rv = write(self->fd, cp, size); |
| 401 | Py_END_ALLOW_THREADS |
| 402 | |
| 403 | if (rv == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 404 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 405 | } else { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 406 | self->ocount += rv; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 407 | } |
| 408 | return PyInt_FromLong(rv); |
| 409 | } |
| 410 | |
| 411 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 412 | oss_writeall(oss_audio_t *self, PyObject *args) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 413 | { |
| 414 | char *cp; |
| 415 | int rv, size; |
| 416 | fd_set write_set_fds; |
| 417 | int select_rv; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 418 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 419 | /* NB. writeall() is only useful in non-blocking mode: according to |
| 420 | Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list |
| 421 | (http://eca.cx/lad/2002/11/0380.html), OSS guarantees that |
| 422 | write() in blocking mode consumes the whole buffer. In blocking |
| 423 | mode, the behaviour of write() and writeall() from Python is |
| 424 | indistinguishable. */ |
| 425 | |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 426 | if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 427 | return NULL; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 428 | |
Charles-François Natali | fda7b37 | 2011-08-28 16:22:33 +0200 | [diff] [blame] | 429 | if (!_PyIsSelectable_fd(self->fd)) { |
| 430 | PyErr_SetString(PyExc_ValueError, |
| 431 | "file descriptor out of range for select"); |
| 432 | return NULL; |
| 433 | } |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 434 | /* use select to wait for audio device to be available */ |
| 435 | FD_ZERO(&write_set_fds); |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 436 | FD_SET(self->fd, &write_set_fds); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 437 | |
| 438 | while (size > 0) { |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 439 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 440 | select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 441 | Py_END_ALLOW_THREADS |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 442 | assert(select_rv != 0); /* no timeout, can't expire */ |
| 443 | if (select_rv == -1) |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 444 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 445 | |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 446 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 447 | rv = write(self->fd, cp, size); |
Greg Ward | 6492785 | 2003-05-23 01:50:37 +0000 | [diff] [blame] | 448 | Py_END_ALLOW_THREADS |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 449 | if (rv == -1) { |
| 450 | if (errno == EAGAIN) { /* buffer is full, try again */ |
| 451 | errno = 0; |
| 452 | continue; |
| 453 | } else /* it's a real error */ |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 454 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 455 | } else { /* wrote rv bytes */ |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 456 | self->ocount += rv; |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 457 | size -= rv; |
| 458 | cp += rv; |
| 459 | } |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 460 | } |
| 461 | Py_INCREF(Py_None); |
| 462 | return Py_None; |
| 463 | } |
| 464 | |
| 465 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 466 | oss_close(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 467 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 468 | if (self->fd >= 0) { |
Greg Ward | b804390 | 2003-05-26 22:47:30 +0000 | [diff] [blame] | 469 | Py_BEGIN_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 470 | close(self->fd); |
Greg Ward | b804390 | 2003-05-26 22:47:30 +0000 | [diff] [blame] | 471 | Py_END_ALLOW_THREADS |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 472 | self->fd = -1; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 473 | } |
| 474 | Py_INCREF(Py_None); |
| 475 | return Py_None; |
| 476 | } |
| 477 | |
| 478 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 479 | oss_fileno(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 480 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 481 | return PyInt_FromLong(self->fd); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 484 | |
| 485 | /* Convenience methods: these generally wrap a couple of ioctls into one |
| 486 | common task. */ |
| 487 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 488 | static PyObject * |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 489 | oss_setparameters(oss_audio_t *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 490 | { |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 491 | int wanted_fmt, wanted_channels, wanted_rate, strict=0; |
| 492 | int fmt, channels, rate; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 493 | |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 494 | if (!PyArg_ParseTuple(args, "iii|i:setparameters", |
| 495 | &wanted_fmt, &wanted_channels, &wanted_rate, |
| 496 | &strict)) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 497 | return NULL; |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 498 | |
| 499 | fmt = wanted_fmt; |
| 500 | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) == -1) { |
| 501 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 502 | } |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 503 | 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 Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 510 | channels = wanted_channels; |
| 511 | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &channels) == -1) { |
| 512 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 513 | } |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 514 | 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 Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 521 | rate = wanted_rate; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 522 | if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) { |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 523 | return PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 524 | } |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 525 | 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 Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 531 | |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 532 | /* Construct the return value: a (fmt, channels, rate) tuple that |
| 533 | tells what the audio hardware was actually set to. */ |
Serhiy Storchaka | 15df36b | 2013-12-17 15:09:45 +0200 | [diff] [blame] | 534 | return Py_BuildValue("(iii)", fmt, channels, rate); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static int |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 538 | _ssize(oss_audio_t *self, int *nchannels, int *ssize) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 539 | { |
| 540 | int fmt; |
| 541 | |
| 542 | fmt = 0; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 543 | if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 544 | return -errno; |
| 545 | |
| 546 | switch (fmt) { |
| 547 | case AFMT_MU_LAW: |
| 548 | case AFMT_A_LAW: |
| 549 | case AFMT_U8: |
| 550 | case AFMT_S8: |
Greg Ward | 38c9266 | 2003-05-29 21:55:41 +0000 | [diff] [blame] | 551 | *ssize = 1; /* 8 bit formats: 1 byte */ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 552 | break; |
| 553 | case AFMT_S16_LE: |
| 554 | case AFMT_S16_BE: |
| 555 | case AFMT_U16_LE: |
| 556 | case AFMT_U16_BE: |
Greg Ward | 84f8ecd | 2003-05-29 23:44:44 +0000 | [diff] [blame] | 557 | *ssize = 2; /* 16 bit formats: 2 byte */ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 558 | break; |
| 559 | case AFMT_MPEG: |
| 560 | case AFMT_IMA_ADPCM: |
| 561 | default: |
| 562 | return -EOPNOTSUPP; |
| 563 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 564 | if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 565 | return -errno; |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 570 | /* bufsize returns the size of the hardware audio buffer in number |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 571 | of samples */ |
| 572 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 573 | oss_bufsize(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 574 | { |
| 575 | audio_buf_info ai; |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 576 | int nchannels=0, ssize=0; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 577 | |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 578 | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 579 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 580 | return NULL; |
| 581 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 582 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 583 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 584 | return NULL; |
| 585 | } |
| 586 | return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize)); |
| 587 | } |
| 588 | |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 589 | /* obufcount returns the number of samples that are available in the |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 590 | hardware for playing */ |
| 591 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 592 | oss_obufcount(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 593 | { |
| 594 | audio_buf_info ai; |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 595 | int nchannels=0, ssize=0; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 596 | |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 597 | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 598 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 599 | return NULL; |
| 600 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 601 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 602 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 603 | return NULL; |
| 604 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 605 | return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) / |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 606 | (ssize * nchannels)); |
| 607 | } |
| 608 | |
| 609 | /* obufcount returns the number of samples that can be played without |
| 610 | blocking */ |
| 611 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 612 | oss_obuffree(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 613 | { |
| 614 | audio_buf_info ai; |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 615 | int nchannels=0, ssize=0; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 616 | |
Thomas Wouters | 3ffa59b | 2006-03-01 22:45:36 +0000 | [diff] [blame] | 617 | if (_ssize(self, &nchannels, &ssize) < 0 || !nchannels || !ssize) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 618 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 619 | return NULL; |
| 620 | } |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 621 | if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 622 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 623 | return NULL; |
| 624 | } |
| 625 | return PyInt_FromLong(ai.bytes / (ssize * nchannels)); |
| 626 | } |
| 627 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 628 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 629 | oss_getptr(oss_audio_t *self, PyObject *unused) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 630 | { |
| 631 | count_info info; |
| 632 | int req; |
| 633 | |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 634 | if (self->mode == O_RDONLY) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 635 | req = SNDCTL_DSP_GETIPTR; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 636 | else |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 637 | req = SNDCTL_DSP_GETOPTR; |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 638 | if (ioctl(self->fd, req, &info) == -1) { |
Greg Ward | 97708bc | 2002-11-30 23:17:10 +0000 | [diff] [blame] | 639 | PyErr_SetFromErrno(PyExc_IOError); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 640 | return NULL; |
| 641 | } |
| 642 | return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr); |
| 643 | } |
| 644 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 645 | |
| 646 | /* ---------------------------------------------------------------------- |
| 647 | * Methods of mixer objects (OSSMixerType) |
| 648 | */ |
| 649 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 650 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 651 | oss_mixer_close(oss_mixer_t *self, PyObject *unused) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 652 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 653 | if (self->fd >= 0) { |
| 654 | close(self->fd); |
| 655 | self->fd = -1; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 656 | } |
| 657 | Py_INCREF(Py_None); |
| 658 | return Py_None; |
| 659 | } |
| 660 | |
| 661 | static PyObject * |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 662 | oss_mixer_fileno(oss_mixer_t *self, PyObject *unused) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 663 | { |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 664 | return PyInt_FromLong(self->fd); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* Simple mixer interface methods */ |
| 668 | |
| 669 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 670 | oss_mixer_controls(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 671 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 672 | return _do_ioctl_1_internal(self->fd, args, "controls", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 673 | SOUND_MIXER_READ_DEVMASK); |
| 674 | } |
| 675 | |
| 676 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 677 | oss_mixer_stereocontrols(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 678 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 679 | return _do_ioctl_1_internal(self->fd, args, "stereocontrols", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 680 | SOUND_MIXER_READ_STEREODEVS); |
| 681 | } |
| 682 | |
| 683 | static PyObject * |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 684 | oss_mixer_reccontrols(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 685 | { |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 686 | return _do_ioctl_1_internal(self->fd, args, "reccontrols", |
Greg Ward | b69bb3d | 2002-12-12 17:35:45 +0000 | [diff] [blame] | 687 | SOUND_MIXER_READ_RECMASK); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static PyObject * |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 691 | oss_mixer_get(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 692 | { |
| 693 | int channel, volume; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 694 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 695 | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 696 | if (!PyArg_ParseTuple(args, "i:get", &channel)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 697 | return NULL; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 698 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 699 | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 700 | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
| 701 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 702 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 703 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 704 | if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 705 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 706 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 707 | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static PyObject * |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 711 | oss_mixer_set(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 712 | { |
| 713 | int channel, volume, leftVol, rightVol; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 714 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 715 | /* Can't use _do_ioctl_1 because of encoded arg thingy. */ |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 716 | if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol)) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 717 | return NULL; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 718 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 719 | if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 720 | PyErr_SetString(OSSAudioError, "Invalid mixer channel specified."); |
| 721 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 722 | } |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 723 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 724 | if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) { |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 725 | PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100."); |
| 726 | return NULL; |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | volume = (rightVol << 8) | leftVol; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 730 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 731 | if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1) |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 732 | return PyErr_SetFromErrno(PyExc_IOError); |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 733 | |
Greg Ward | e703766 | 2002-12-30 03:01:48 +0000 | [diff] [blame] | 734 | return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static PyObject * |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 738 | oss_mixer_get_recsrc(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 739 | { |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 740 | return _do_ioctl_1_internal(self->fd, args, "get_recsrc", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 741 | SOUND_MIXER_READ_RECSRC); |
| 742 | } |
| 743 | |
| 744 | static PyObject * |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 745 | oss_mixer_set_recsrc(oss_mixer_t *self, PyObject *args) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 746 | { |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 747 | return _do_ioctl_1(self->fd, args, "set_recsrc", |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 748 | SOUND_MIXER_WRITE_RECSRC); |
| 749 | } |
| 750 | |
| 751 | |
Greg Ward | da1cacb | 2002-12-31 03:02:23 +0000 | [diff] [blame] | 752 | /* ---------------------------------------------------------------------- |
| 753 | * Method tables and other bureaucracy |
| 754 | */ |
| 755 | |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 756 | static PyMethodDef oss_methods[] = { |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 757 | /* Regular file methods */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 758 | { "read", (PyCFunction)oss_read, METH_VARARGS }, |
| 759 | { "write", (PyCFunction)oss_write, METH_VARARGS }, |
| 760 | { "writeall", (PyCFunction)oss_writeall, METH_VARARGS }, |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 761 | { "close", (PyCFunction)oss_close, METH_NOARGS }, |
| 762 | { "fileno", (PyCFunction)oss_fileno, METH_NOARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 763 | |
| 764 | /* Simple ioctl wrappers */ |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 765 | { "nonblock", (PyCFunction)oss_nonblock, METH_NOARGS }, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 766 | { "setfmt", (PyCFunction)oss_setfmt, METH_VARARGS }, |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 767 | { "getfmts", (PyCFunction)oss_getfmts, METH_NOARGS }, |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 768 | { "channels", (PyCFunction)oss_channels, METH_VARARGS }, |
| 769 | { "speed", (PyCFunction)oss_speed, METH_VARARGS }, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 770 | { "sync", (PyCFunction)oss_sync, METH_VARARGS }, |
| 771 | { "reset", (PyCFunction)oss_reset, METH_VARARGS }, |
| 772 | { "post", (PyCFunction)oss_post, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 773 | |
| 774 | /* Convenience methods -- wrap a couple of ioctls together */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 775 | { "setparameters", (PyCFunction)oss_setparameters, METH_VARARGS }, |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 776 | { "bufsize", (PyCFunction)oss_bufsize, METH_NOARGS }, |
| 777 | { "obufcount", (PyCFunction)oss_obufcount, METH_NOARGS }, |
| 778 | { "obuffree", (PyCFunction)oss_obuffree, METH_NOARGS }, |
| 779 | { "getptr", (PyCFunction)oss_getptr, METH_NOARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 780 | |
| 781 | /* Aliases for backwards compatibility */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 782 | { "flush", (PyCFunction)oss_sync, METH_VARARGS }, |
Greg Ward | 131bce0 | 2002-11-30 22:56:44 +0000 | [diff] [blame] | 783 | |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 784 | { NULL, NULL} /* sentinel */ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 785 | }; |
| 786 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 787 | static PyMethodDef oss_mixer_methods[] = { |
| 788 | /* Regular file method - OSS mixers are ioctl-only interface */ |
Georg Brandl | 96a8c39 | 2006-05-29 21:04:52 +0000 | [diff] [blame] | 789 | { "close", (PyCFunction)oss_mixer_close, METH_NOARGS }, |
| 790 | { "fileno", (PyCFunction)oss_mixer_fileno, METH_NOARGS }, |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 791 | |
| 792 | /* Simple ioctl wrappers */ |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 793 | { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS }, |
Greg Ward | 2d6f9a9 | 2002-12-31 02:54:43 +0000 | [diff] [blame] | 794 | { "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS}, |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 795 | { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS}, |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 796 | { "get", (PyCFunction)oss_mixer_get, METH_VARARGS }, |
| 797 | { "set", (PyCFunction)oss_mixer_set, METH_VARARGS }, |
Greg Ward | f05aa10 | 2002-12-30 23:19:32 +0000 | [diff] [blame] | 798 | { "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS }, |
| 799 | { "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS }, |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 800 | |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 801 | { NULL, NULL} |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 802 | }; |
| 803 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 804 | static PyObject * |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 805 | oss_getattr(oss_audio_t *self, char *name) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 806 | { |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 807 | PyObject * rval = NULL; |
| 808 | if (strcmp(name, "closed") == 0) { |
| 809 | rval = (self->fd == -1) ? Py_True : Py_False; |
| 810 | Py_INCREF(rval); |
| 811 | } |
| 812 | else if (strcmp(name, "name") == 0) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 813 | rval = PyString_FromString(self->devicename); |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 814 | } |
| 815 | else if (strcmp(name, "mode") == 0) { |
| 816 | /* No need for a "default" in this switch: from newossobject(), |
| 817 | self->mode can only be one of these three values. */ |
| 818 | switch(self->mode) { |
| 819 | case O_RDONLY: |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 820 | rval = PyString_FromString("r"); |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 821 | break; |
| 822 | case O_RDWR: |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 823 | rval = PyString_FromString("rw"); |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 824 | break; |
| 825 | case O_WRONLY: |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 826 | rval = PyString_FromString("w"); |
Greg Ward | 50682d0 | 2005-03-07 01:41:11 +0000 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | } |
| 830 | else { |
| 831 | rval = Py_FindMethod(oss_methods, (PyObject *)self, name); |
| 832 | } |
| 833 | return rval; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 836 | static PyObject * |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 837 | oss_mixer_getattr(oss_mixer_t *self, char *name) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 838 | { |
Greg Ward | 58ae13c | 2002-12-31 03:07:21 +0000 | [diff] [blame] | 839 | return Py_FindMethod(oss_mixer_methods, (PyObject *)self, name); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 842 | static PyTypeObject OSSAudioType = { |
Martin v. Löwis | 6819210 | 2007-07-21 06:55:02 +0000 | [diff] [blame] | 843 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 844 | "ossaudiodev.oss_audio_device", /*tp_name*/ |
Greg Ward | 499b73e | 2002-12-31 03:04:52 +0000 | [diff] [blame] | 845 | sizeof(oss_audio_t), /*tp_size*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 846 | 0, /*tp_itemsize*/ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 847 | /* methods */ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 848 | (destructor)oss_dealloc, /*tp_dealloc*/ |
| 849 | 0, /*tp_print*/ |
| 850 | (getattrfunc)oss_getattr, /*tp_getattr*/ |
| 851 | 0, /*tp_setattr*/ |
| 852 | 0, /*tp_compare*/ |
| 853 | 0, /*tp_repr*/ |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 854 | }; |
| 855 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 856 | static PyTypeObject OSSMixerType = { |
Martin v. Löwis | 6819210 | 2007-07-21 06:55:02 +0000 | [diff] [blame] | 857 | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 858 | "ossaudiodev.oss_mixer_device", /*tp_name*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 859 | sizeof(oss_mixer_t), /*tp_size*/ |
| 860 | 0, /*tp_itemsize*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 861 | /* methods */ |
| 862 | (destructor)oss_mixer_dealloc, /*tp_dealloc*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 863 | 0, /*tp_print*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 864 | (getattrfunc)oss_mixer_getattr, /*tp_getattr*/ |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 865 | 0, /*tp_setattr*/ |
| 866 | 0, /*tp_compare*/ |
| 867 | 0, /*tp_repr*/ |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 868 | }; |
| 869 | |
| 870 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 871 | static PyObject * |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 872 | ossopen(PyObject *self, PyObject *args) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 873 | { |
Greg Ward | 8c6b6a9 | 2002-12-11 14:43:13 +0000 | [diff] [blame] | 874 | return (PyObject *)newossobject(args); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 877 | static PyObject * |
| 878 | ossopenmixer(PyObject *self, PyObject *args) |
| 879 | { |
| 880 | return (PyObject *)newossmixerobject(args); |
| 881 | } |
| 882 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 883 | static PyMethodDef ossaudiodev_methods[] = { |
| 884 | { "open", ossopen, METH_VARARGS }, |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 885 | { "openmixer", ossopenmixer, METH_VARARGS }, |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 886 | { 0, 0 }, |
| 887 | }; |
| 888 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 889 | |
| 890 | #define _EXPORT_INT(mod, name) \ |
| 891 | if (PyModule_AddIntConstant(mod, #name, (long) (name)) == -1) return; |
| 892 | |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 893 | |
| 894 | static char *control_labels[] = SOUND_DEVICE_LABELS; |
| 895 | static char *control_names[] = SOUND_DEVICE_NAMES; |
| 896 | |
| 897 | |
| 898 | static int |
| 899 | build_namelists (PyObject *module) |
| 900 | { |
| 901 | PyObject *labels; |
| 902 | PyObject *names; |
| 903 | PyObject *s; |
| 904 | int num_controls; |
| 905 | int i; |
| 906 | |
| 907 | num_controls = sizeof(control_labels) / sizeof(control_labels[0]); |
| 908 | assert(num_controls == sizeof(control_names) / sizeof(control_names[0])); |
| 909 | |
| 910 | labels = PyList_New(num_controls); |
| 911 | names = PyList_New(num_controls); |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 912 | if (labels == NULL || names == NULL) |
| 913 | goto error2; |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 914 | for (i = 0; i < num_controls; i++) { |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 915 | s = PyString_FromString(control_labels[i]); |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 916 | if (s == NULL) |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 917 | goto error2; |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 918 | PyList_SET_ITEM(labels, i, s); |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 919 | |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 920 | s = PyString_FromString(control_names[i]); |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 921 | if (s == NULL) |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 922 | goto error2; |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 923 | PyList_SET_ITEM(names, i, s); |
| 924 | } |
| 925 | |
| 926 | if (PyModule_AddObject(module, "control_labels", labels) == -1) |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 927 | goto error2; |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 928 | if (PyModule_AddObject(module, "control_names", names) == -1) |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 929 | goto error1; |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 930 | |
| 931 | return 0; |
Georg Brandl | 5c170fd | 2006-03-17 19:03:25 +0000 | [diff] [blame] | 932 | |
| 933 | error2: |
| 934 | Py_XDECREF(labels); |
| 935 | error1: |
| 936 | Py_XDECREF(names); |
| 937 | return -1; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 938 | } |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 939 | |
| 940 | |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 941 | void |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 942 | initossaudiodev(void) |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 943 | { |
| 944 | PyObject *m; |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 945 | |
Greg Ward | 9a568eb | 2002-11-30 23:20:09 +0000 | [diff] [blame] | 946 | m = Py_InitModule("ossaudiodev", ossaudiodev_methods); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 947 | if (m == NULL) |
| 948 | return; |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 949 | |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 950 | OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError", |
| 951 | NULL, NULL); |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 952 | if (OSSAudioError) { |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 953 | /* Each call to PyModule_AddObject decrefs it; compensate: */ |
| 954 | Py_INCREF(OSSAudioError); |
| 955 | Py_INCREF(OSSAudioError); |
Greg Ward | ad4d9b9 | 2002-12-30 03:02:22 +0000 | [diff] [blame] | 956 | PyModule_AddObject(m, "error", OSSAudioError); |
Greg Ward | d676906 | 2003-05-29 21:53:06 +0000 | [diff] [blame] | 957 | PyModule_AddObject(m, "OSSAudioError", OSSAudioError); |
| 958 | } |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 959 | |
Greg Ward | 744f0fd | 2002-12-31 03:23:59 +0000 | [diff] [blame] | 960 | /* Build 'control_labels' and 'control_names' lists and add them |
| 961 | to the module. */ |
| 962 | if (build_namelists(m) == -1) /* XXX what to do here? */ |
| 963 | return; |
| 964 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 965 | /* Expose the audio format numbers -- essential! */ |
| 966 | _EXPORT_INT(m, AFMT_QUERY); |
| 967 | _EXPORT_INT(m, AFMT_MU_LAW); |
| 968 | _EXPORT_INT(m, AFMT_A_LAW); |
| 969 | _EXPORT_INT(m, AFMT_IMA_ADPCM); |
| 970 | _EXPORT_INT(m, AFMT_U8); |
| 971 | _EXPORT_INT(m, AFMT_S16_LE); |
| 972 | _EXPORT_INT(m, AFMT_S16_BE); |
| 973 | _EXPORT_INT(m, AFMT_S8); |
| 974 | _EXPORT_INT(m, AFMT_U16_LE); |
| 975 | _EXPORT_INT(m, AFMT_U16_BE); |
| 976 | _EXPORT_INT(m, AFMT_MPEG); |
Andrew M. Kuchling | fe62bc9 | 2003-02-13 13:27:07 +0000 | [diff] [blame] | 977 | #ifdef AFMT_AC3 |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 978 | _EXPORT_INT(m, AFMT_AC3); |
Andrew M. Kuchling | fe62bc9 | 2003-02-13 13:27:07 +0000 | [diff] [blame] | 979 | #endif |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 980 | #ifdef AFMT_S16_NE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 981 | _EXPORT_INT(m, AFMT_S16_NE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 982 | #endif |
Greg Ward | 0f26054 | 2005-03-28 02:40:46 +0000 | [diff] [blame] | 983 | #ifdef AFMT_U16_NE |
| 984 | _EXPORT_INT(m, AFMT_U16_NE); |
| 985 | #endif |
| 986 | #ifdef AFMT_S32_LE |
| 987 | _EXPORT_INT(m, AFMT_S32_LE); |
| 988 | #endif |
| 989 | #ifdef AFMT_S32_BE |
| 990 | _EXPORT_INT(m, AFMT_S32_BE); |
| 991 | #endif |
| 992 | #ifdef AFMT_MPEG |
| 993 | _EXPORT_INT(m, AFMT_MPEG); |
| 994 | #endif |
Guido van Rossum | 0741f80 | 2003-06-02 14:15:34 +0000 | [diff] [blame] | 995 | |
Greg Ward | 37897c2 | 2002-12-30 02:43:36 +0000 | [diff] [blame] | 996 | /* Expose the sound mixer device numbers. */ |
Greg Ward | 7b43c68 | 2002-12-30 02:29:28 +0000 | [diff] [blame] | 997 | _EXPORT_INT(m, SOUND_MIXER_NRDEVICES); |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 998 | _EXPORT_INT(m, SOUND_MIXER_VOLUME); |
| 999 | _EXPORT_INT(m, SOUND_MIXER_BASS); |
| 1000 | _EXPORT_INT(m, SOUND_MIXER_TREBLE); |
| 1001 | _EXPORT_INT(m, SOUND_MIXER_SYNTH); |
| 1002 | _EXPORT_INT(m, SOUND_MIXER_PCM); |
| 1003 | _EXPORT_INT(m, SOUND_MIXER_SPEAKER); |
| 1004 | _EXPORT_INT(m, SOUND_MIXER_LINE); |
| 1005 | _EXPORT_INT(m, SOUND_MIXER_MIC); |
| 1006 | _EXPORT_INT(m, SOUND_MIXER_CD); |
| 1007 | _EXPORT_INT(m, SOUND_MIXER_IMIX); |
| 1008 | _EXPORT_INT(m, SOUND_MIXER_ALTPCM); |
| 1009 | _EXPORT_INT(m, SOUND_MIXER_RECLEV); |
| 1010 | _EXPORT_INT(m, SOUND_MIXER_IGAIN); |
| 1011 | _EXPORT_INT(m, SOUND_MIXER_OGAIN); |
| 1012 | _EXPORT_INT(m, SOUND_MIXER_LINE1); |
| 1013 | _EXPORT_INT(m, SOUND_MIXER_LINE2); |
| 1014 | _EXPORT_INT(m, SOUND_MIXER_LINE3); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1015 | #ifdef SOUND_MIXER_DIGITAL1 |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1016 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL1); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1017 | #endif |
| 1018 | #ifdef SOUND_MIXER_DIGITAL2 |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1019 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL2); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1020 | #endif |
| 1021 | #ifdef SOUND_MIXER_DIGITAL3 |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1022 | _EXPORT_INT(m, SOUND_MIXER_DIGITAL3); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1023 | #endif |
| 1024 | #ifdef SOUND_MIXER_PHONEIN |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1025 | _EXPORT_INT(m, SOUND_MIXER_PHONEIN); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1026 | #endif |
| 1027 | #ifdef SOUND_MIXER_PHONEOUT |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1028 | _EXPORT_INT(m, SOUND_MIXER_PHONEOUT); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1029 | #endif |
| 1030 | #ifdef SOUND_MIXER_VIDEO |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1031 | _EXPORT_INT(m, SOUND_MIXER_VIDEO); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1032 | #endif |
| 1033 | #ifdef SOUND_MIXER_RADIO |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1034 | _EXPORT_INT(m, SOUND_MIXER_RADIO); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1035 | #endif |
| 1036 | #ifdef SOUND_MIXER_MONITOR |
Greg Ward | 3d9994d | 2002-12-11 15:12:01 +0000 | [diff] [blame] | 1037 | _EXPORT_INT(m, SOUND_MIXER_MONITOR); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1038 | #endif |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 1039 | |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1040 | /* Expose all the ioctl numbers for masochists who like to do this |
| 1041 | stuff directly. */ |
| 1042 | _EXPORT_INT(m, SNDCTL_COPR_HALT); |
| 1043 | _EXPORT_INT(m, SNDCTL_COPR_LOAD); |
| 1044 | _EXPORT_INT(m, SNDCTL_COPR_RCODE); |
| 1045 | _EXPORT_INT(m, SNDCTL_COPR_RCVMSG); |
| 1046 | _EXPORT_INT(m, SNDCTL_COPR_RDATA); |
| 1047 | _EXPORT_INT(m, SNDCTL_COPR_RESET); |
| 1048 | _EXPORT_INT(m, SNDCTL_COPR_RUN); |
| 1049 | _EXPORT_INT(m, SNDCTL_COPR_SENDMSG); |
| 1050 | _EXPORT_INT(m, SNDCTL_COPR_WCODE); |
| 1051 | _EXPORT_INT(m, SNDCTL_COPR_WDATA); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1052 | #ifdef SNDCTL_DSP_BIND_CHANNEL |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1053 | _EXPORT_INT(m, SNDCTL_DSP_BIND_CHANNEL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1054 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1055 | _EXPORT_INT(m, SNDCTL_DSP_CHANNELS); |
| 1056 | _EXPORT_INT(m, SNDCTL_DSP_GETBLKSIZE); |
| 1057 | _EXPORT_INT(m, SNDCTL_DSP_GETCAPS); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1058 | #ifdef SNDCTL_DSP_GETCHANNELMASK |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1059 | _EXPORT_INT(m, SNDCTL_DSP_GETCHANNELMASK); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1060 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1061 | _EXPORT_INT(m, SNDCTL_DSP_GETFMTS); |
| 1062 | _EXPORT_INT(m, SNDCTL_DSP_GETIPTR); |
| 1063 | _EXPORT_INT(m, SNDCTL_DSP_GETISPACE); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1064 | #ifdef SNDCTL_DSP_GETODELAY |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1065 | _EXPORT_INT(m, SNDCTL_DSP_GETODELAY); |
Greg Ward | fd0283e | 2004-05-11 01:34:55 +0000 | [diff] [blame] | 1066 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1067 | _EXPORT_INT(m, SNDCTL_DSP_GETOPTR); |
| 1068 | _EXPORT_INT(m, SNDCTL_DSP_GETOSPACE); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1069 | #ifdef SNDCTL_DSP_GETSPDIF |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1070 | _EXPORT_INT(m, SNDCTL_DSP_GETSPDIF); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1071 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1072 | _EXPORT_INT(m, SNDCTL_DSP_GETTRIGGER); |
| 1073 | _EXPORT_INT(m, SNDCTL_DSP_MAPINBUF); |
| 1074 | _EXPORT_INT(m, SNDCTL_DSP_MAPOUTBUF); |
| 1075 | _EXPORT_INT(m, SNDCTL_DSP_NONBLOCK); |
| 1076 | _EXPORT_INT(m, SNDCTL_DSP_POST); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1077 | #ifdef SNDCTL_DSP_PROFILE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1078 | _EXPORT_INT(m, SNDCTL_DSP_PROFILE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1079 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1080 | _EXPORT_INT(m, SNDCTL_DSP_RESET); |
| 1081 | _EXPORT_INT(m, SNDCTL_DSP_SAMPLESIZE); |
| 1082 | _EXPORT_INT(m, SNDCTL_DSP_SETDUPLEX); |
| 1083 | _EXPORT_INT(m, SNDCTL_DSP_SETFMT); |
| 1084 | _EXPORT_INT(m, SNDCTL_DSP_SETFRAGMENT); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1085 | #ifdef SNDCTL_DSP_SETSPDIF |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1086 | _EXPORT_INT(m, SNDCTL_DSP_SETSPDIF); |
Neal Norwitz | faa7b9b | 2003-01-10 21:27:54 +0000 | [diff] [blame] | 1087 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1088 | _EXPORT_INT(m, SNDCTL_DSP_SETSYNCRO); |
| 1089 | _EXPORT_INT(m, SNDCTL_DSP_SETTRIGGER); |
| 1090 | _EXPORT_INT(m, SNDCTL_DSP_SPEED); |
| 1091 | _EXPORT_INT(m, SNDCTL_DSP_STEREO); |
| 1092 | _EXPORT_INT(m, SNDCTL_DSP_SUBDIVIDE); |
| 1093 | _EXPORT_INT(m, SNDCTL_DSP_SYNC); |
| 1094 | _EXPORT_INT(m, SNDCTL_FM_4OP_ENABLE); |
| 1095 | _EXPORT_INT(m, SNDCTL_FM_LOAD_INSTR); |
| 1096 | _EXPORT_INT(m, SNDCTL_MIDI_INFO); |
| 1097 | _EXPORT_INT(m, SNDCTL_MIDI_MPUCMD); |
| 1098 | _EXPORT_INT(m, SNDCTL_MIDI_MPUMODE); |
| 1099 | _EXPORT_INT(m, SNDCTL_MIDI_PRETIME); |
| 1100 | _EXPORT_INT(m, SNDCTL_SEQ_CTRLRATE); |
| 1101 | _EXPORT_INT(m, SNDCTL_SEQ_GETINCOUNT); |
| 1102 | _EXPORT_INT(m, SNDCTL_SEQ_GETOUTCOUNT); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1103 | #ifdef SNDCTL_SEQ_GETTIME |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1104 | _EXPORT_INT(m, SNDCTL_SEQ_GETTIME); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1105 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1106 | _EXPORT_INT(m, SNDCTL_SEQ_NRMIDIS); |
| 1107 | _EXPORT_INT(m, SNDCTL_SEQ_NRSYNTHS); |
| 1108 | _EXPORT_INT(m, SNDCTL_SEQ_OUTOFBAND); |
| 1109 | _EXPORT_INT(m, SNDCTL_SEQ_PANIC); |
| 1110 | _EXPORT_INT(m, SNDCTL_SEQ_PERCMODE); |
| 1111 | _EXPORT_INT(m, SNDCTL_SEQ_RESET); |
| 1112 | _EXPORT_INT(m, SNDCTL_SEQ_RESETSAMPLES); |
| 1113 | _EXPORT_INT(m, SNDCTL_SEQ_SYNC); |
| 1114 | _EXPORT_INT(m, SNDCTL_SEQ_TESTMIDI); |
| 1115 | _EXPORT_INT(m, SNDCTL_SEQ_THRESHOLD); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1116 | #ifdef SNDCTL_SYNTH_CONTROL |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1117 | _EXPORT_INT(m, SNDCTL_SYNTH_CONTROL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1118 | #endif |
| 1119 | #ifdef SNDCTL_SYNTH_ID |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1120 | _EXPORT_INT(m, SNDCTL_SYNTH_ID); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1121 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1122 | _EXPORT_INT(m, SNDCTL_SYNTH_INFO); |
| 1123 | _EXPORT_INT(m, SNDCTL_SYNTH_MEMAVL); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1124 | #ifdef SNDCTL_SYNTH_REMOVESAMPLE |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1125 | _EXPORT_INT(m, SNDCTL_SYNTH_REMOVESAMPLE); |
Neal Norwitz | d156c2d | 2003-02-02 17:59:06 +0000 | [diff] [blame] | 1126 | #endif |
Greg Ward | 1e0f57d | 2002-11-30 23:05:26 +0000 | [diff] [blame] | 1127 | _EXPORT_INT(m, SNDCTL_TMR_CONTINUE); |
| 1128 | _EXPORT_INT(m, SNDCTL_TMR_METRONOME); |
| 1129 | _EXPORT_INT(m, SNDCTL_TMR_SELECT); |
| 1130 | _EXPORT_INT(m, SNDCTL_TMR_SOURCE); |
| 1131 | _EXPORT_INT(m, SNDCTL_TMR_START); |
| 1132 | _EXPORT_INT(m, SNDCTL_TMR_STOP); |
| 1133 | _EXPORT_INT(m, SNDCTL_TMR_TEMPO); |
| 1134 | _EXPORT_INT(m, SNDCTL_TMR_TIMEBASE); |
Greg Ward | 04613a9 | 2002-11-30 22:47:45 +0000 | [diff] [blame] | 1135 | } |