* Renamed to ossaudiodev and rearranged/revised/hacked up
* by Greg Ward <gward@python.net>, November 2002.
* Mixer interface by Nicholas FitzRoy-Dale <wzdd@lardcave.net>, Dec 2002.
- *
+ *
* (c) 2000 Peter Bosch. All Rights Reserved.
* (c) 2002 Gregory P. Ward. All Rights Reserved.
* (c) 2002 Python Software Foundation. All Rights Reserved.
char *basedev = NULL;
int fd;
oss_mixer_t *self;
-
+
if (!PyArg_ParseTuple(arg, "|s", &basedev)) {
return NULL;
}
-
+
if (basedev == NULL) {
basedev = getenv("MIXERDEV");
if (basedev == NULL) /* MIXERDEV not set */
close(fd);
return NULL;
}
-
+
self->fd = fd;
-
+
return self;
}
{
return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
}
-
+
static PyObject *
oss_reset(oss_audio_t *self, PyObject *args)
{
return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
}
-
+
static PyObject *
oss_post(oss_audio_t *self, PyObject *args)
{
int size, count;
char *cp;
PyObject *rv;
-
+
if (!PyArg_ParseTuple(args, "i:read", &size))
return NULL;
rv = PyString_FromStringAndSize(NULL, size);
int rv, size;
fd_set write_set_fds;
int select_rv;
-
+
/* NB. writeall() is only useful in non-blocking mode: according to
Guenter Geiger <geiger@xdv.org> on the linux-audio-dev list
(http://eca.cx/lad/2002/11/0380.html), OSS guarantees that
mode, the behaviour of write() and writeall() from Python is
indistinguishable. */
- if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
+ if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
return NULL;
/* use select to wait for audio device to be available */
static PyObject *
oss_fileno(oss_audio_t *self, PyObject *args)
{
- if (!PyArg_ParseTuple(args, ":fileno"))
+ if (!PyArg_ParseTuple(args, ":fileno"))
return NULL;
return PyInt_FromLong(self->fd);
}
"unable to set requested rate (wanted %d, got %d)",
wanted_rate, rate);
}
-
+
/* Construct the return value: a (fmt, channels, rate) tuple that
tells what the audio hardware was actually set to. */
rv = PyTuple_New(3);
int fmt;
fmt = 0;
- if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
+ if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
return -errno;
switch (fmt) {
}
-/* bufsize returns the size of the hardware audio buffer in number
+/* bufsize returns the size of the hardware audio buffer in number
of samples */
static PyObject *
oss_bufsize(oss_audio_t *self, PyObject *args)
return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
}
-/* obufcount returns the number of samples that are available in the
+/* obufcount returns the number of samples that are available in the
hardware for playing */
static PyObject *
oss_obufcount(oss_audio_t *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
+ return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
(ssize * nchannels));
}
if (!PyArg_ParseTuple(args, ":getptr"))
return NULL;
-
+
if (self->mode == O_RDONLY)
req = SNDCTL_DSP_GETIPTR;
else
static PyObject *
oss_mixer_fileno(oss_mixer_t *self, PyObject *args)
{
- if (!PyArg_ParseTuple(args, ":fileno"))
+ if (!PyArg_ParseTuple(args, ":fileno"))
return NULL;
return PyInt_FromLong(self->fd);
}
oss_mixer_get(oss_mixer_t *self, PyObject *args)
{
int channel, volume;
-
+
/* Can't use _do_ioctl_1 because of encoded arg thingy. */
if (!PyArg_ParseTuple(args, "i:get", &channel))
return NULL;
-
+
if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
return NULL;
}
-
+
if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
-
+
return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
}
oss_mixer_set(oss_mixer_t *self, PyObject *args)
{
int channel, volume, leftVol, rightVol;
-
+
/* Can't use _do_ioctl_1 because of encoded arg thingy. */
if (!PyArg_ParseTuple(args, "i(ii):set", &channel, &leftVol, &rightVol))
return NULL;
-
+
if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
return NULL;
}
-
+
if (leftVol < 0 || rightVol < 0 || leftVol > 100 || rightVol > 100) {
PyErr_SetString(OSSAudioError, "Volumes must be between 0 and 100.");
return NULL;
}
volume = (rightVol << 8) | leftVol;
-
+
if (ioctl(self->fd, MIXER_WRITE(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
-
+
return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
}
static PyMethodDef oss_mixer_methods[] = {
/* Regular file method - OSS mixers are ioctl-only interface */
- { "close", (PyCFunction)oss_mixer_close, METH_VARARGS },
+ { "close", (PyCFunction)oss_mixer_close, METH_VARARGS },
{ "fileno", (PyCFunction)oss_mixer_fileno, METH_VARARGS },
/* Simple ioctl wrappers */
- { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
+ { "controls", (PyCFunction)oss_mixer_controls, METH_VARARGS },
{ "stereocontrols", (PyCFunction)oss_mixer_stereocontrols, METH_VARARGS},
- { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
+ { "reccontrols", (PyCFunction)oss_mixer_reccontrols, METH_VARARGS},
{ "get", (PyCFunction)oss_mixer_get, METH_VARARGS },
{ "set", (PyCFunction)oss_mixer_set, METH_VARARGS },
{ "get_recsrc", (PyCFunction)oss_mixer_get_recsrc, METH_VARARGS },
{ "set_recsrc", (PyCFunction)oss_mixer_set_recsrc, METH_VARARGS },
-
+
{ NULL, NULL}
};
if (s == NULL)
return -1;
PyList_SET_ITEM(labels, i, s);
-
+
s = PyString_FromString(control_names[i]);
if (s == NULL)
return -1;
return -1;
return 0;
-}
+}
void
initossaudiodev(void)
{
PyObject *m;
-
+
m = Py_InitModule("ossaudiodev", ossaudiodev_methods);
- OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError", NULL, NULL);
+ OSSAudioError = PyErr_NewException("ossaudiodev.OSSAudioError",
+ NULL, NULL);
if (OSSAudioError) {
- /* Each call to PyModule_AddObject decrefs it; compensate: */
- Py_INCREF(OSSAudioError);
- Py_INCREF(OSSAudioError);
+ /* Each call to PyModule_AddObject decrefs it; compensate: */
+ Py_INCREF(OSSAudioError);
+ Py_INCREF(OSSAudioError);
PyModule_AddObject(m, "error", OSSAudioError);
PyModule_AddObject(m, "OSSAudioError", OSSAudioError);
}
#ifdef AFMT_S16_NE
_EXPORT_INT(m, AFMT_S16_NE);
#endif
-
+
/* Expose the sound mixer device numbers. */
_EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
_EXPORT_INT(m, SOUND_MIXER_VOLUME);