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