mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Untabify C files. Will watch buildbots.
This commit is contained in:
parent
368ede83d9
commit
c83ea137d7
318 changed files with 198669 additions and 198669 deletions
|
@ -1,14 +1,14 @@
|
|||
/* Hey Emacs, this is -*-C-*-
|
||||
/* Hey Emacs, this is -*-C-*-
|
||||
******************************************************************************
|
||||
* linuxaudiodev.c -- Linux audio device for python.
|
||||
*
|
||||
*
|
||||
* Author : Peter Bosch
|
||||
* Created On : Thu Mar 2 21:10:33 2000
|
||||
* Status : Unknown, Use with caution!
|
||||
*
|
||||
*
|
||||
* Unless other notices are present in any part of this file
|
||||
* explicitly claiming copyrights for other people and/or
|
||||
* organizations, the contents of this file is fully copyright
|
||||
* explicitly claiming copyrights for other people and/or
|
||||
* organizations, the contents of this file is fully copyright
|
||||
* (C) 2000 Peter Bosch, all rights reserved.
|
||||
******************************************************************************
|
||||
*/
|
||||
|
@ -43,11 +43,11 @@ typedef unsigned long uint32_t;
|
|||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
int x_fd; /* The open file */
|
||||
int x_fd; /* The open file */
|
||||
int x_mode; /* file mode */
|
||||
int x_icount; /* Input count */
|
||||
int x_ocount; /* Output count */
|
||||
uint32_t x_afmts; /* Audio formats supported by hardware*/
|
||||
int x_icount; /* Input count */
|
||||
int x_ocount; /* Output count */
|
||||
uint32_t x_afmts; /* Audio formats supported by hardware*/
|
||||
} lad_t;
|
||||
|
||||
/* XXX several format defined in soundcard.h are not supported,
|
||||
|
@ -55,19 +55,19 @@ typedef struct {
|
|||
*/
|
||||
|
||||
static struct {
|
||||
int a_bps;
|
||||
uint32_t a_fmt;
|
||||
int a_bps;
|
||||
uint32_t a_fmt;
|
||||
char *a_name;
|
||||
} audio_types[] = {
|
||||
{ 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" },
|
||||
{ 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" },
|
||||
{ 8, AFMT_U8, "linear unsigned 8-bit audio" },
|
||||
{ 8, AFMT_S8, "linear signed 8-bit audio" },
|
||||
{ 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" },
|
||||
{ 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" },
|
||||
{ 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" },
|
||||
{ 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" },
|
||||
{ 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" },
|
||||
{ 8, AFMT_MU_LAW, "logarithmic mu-law 8-bit audio" },
|
||||
{ 8, AFMT_A_LAW, "logarithmic A-law 8-bit audio" },
|
||||
{ 8, AFMT_U8, "linear unsigned 8-bit audio" },
|
||||
{ 8, AFMT_S8, "linear signed 8-bit audio" },
|
||||
{ 16, AFMT_U16_BE, "linear unsigned 16-bit big-endian audio" },
|
||||
{ 16, AFMT_U16_LE, "linear unsigned 16-bit little-endian audio" },
|
||||
{ 16, AFMT_S16_BE, "linear signed 16-bit big-endian audio" },
|
||||
{ 16, AFMT_S16_LE, "linear signed 16-bit little-endian audio" },
|
||||
{ 16, AFMT_S16_NE, "linear signed 16-bit native-endian audio" },
|
||||
};
|
||||
|
||||
static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]);
|
||||
|
@ -108,7 +108,7 @@ newladobject(PyObject *arg)
|
|||
/* Open the correct device. The base device name comes from the
|
||||
* AUDIODEV environment variable first, then /dev/dsp. The
|
||||
* control device tacks "ctl" onto the base device name.
|
||||
*
|
||||
*
|
||||
* Note that the only difference between /dev/audio and /dev/dsp
|
||||
* is that the former uses logarithmic mu-law encoding and the
|
||||
* latter uses 8-bit unsigned encoding.
|
||||
|
@ -149,7 +149,7 @@ lad_dealloc(lad_t *xp)
|
|||
{
|
||||
/* if already closed, don't reclose it */
|
||||
if (xp->x_fd != -1)
|
||||
close(xp->x_fd);
|
||||
close(xp->x_fd);
|
||||
PyObject_Del(xp);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ lad_read(lad_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);
|
||||
|
@ -184,36 +184,36 @@ lad_write(lad_t *self, PyObject *args)
|
|||
fd_set write_set_fds;
|
||||
struct timeval tv;
|
||||
int select_retval;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
|
||||
return NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
|
||||
return NULL;
|
||||
|
||||
/* use select to wait for audio device to be available */
|
||||
FD_ZERO(&write_set_fds);
|
||||
FD_SET(self->x_fd, &write_set_fds);
|
||||
tv.tv_sec = 4; /* timeout values */
|
||||
tv.tv_usec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
while (size > 0) {
|
||||
select_retval = select(self->x_fd+1, NULL, &write_set_fds, NULL, &tv);
|
||||
tv.tv_sec = 1; tv.tv_usec = 0; /* willing to wait this long next time*/
|
||||
if (select_retval) {
|
||||
if ((rv = write(self->x_fd, cp, size)) == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
} else {
|
||||
errno = 0; /* EAGAIN: buffer is full, try again */
|
||||
}
|
||||
if (errno != EAGAIN) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
} else {
|
||||
errno = 0; /* EAGAIN: buffer is full, try again */
|
||||
}
|
||||
} else {
|
||||
self->x_ocount += rv;
|
||||
size -= rv;
|
||||
cp += rv;
|
||||
}
|
||||
self->x_ocount += rv;
|
||||
size -= rv;
|
||||
cp += rv;
|
||||
}
|
||||
} else {
|
||||
/* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
/* printf("Not able to write to linux audio device within %ld seconds\n", tv.tv_sec); */
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
|
@ -244,47 +244,47 @@ lad_setparameters(lad_t *self, PyObject *args)
|
|||
if (!PyArg_ParseTuple(args, "iiii|i:setparameters",
|
||||
&rate, &ssize, &nchannels, &fmt, &emulate))
|
||||
return NULL;
|
||||
|
||||
|
||||
if (rate < 0) {
|
||||
PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
|
||||
rate);
|
||||
return NULL;
|
||||
PyErr_Format(PyExc_ValueError, "expected rate >= 0, not %d",
|
||||
rate);
|
||||
return NULL;
|
||||
}
|
||||
if (ssize < 0) {
|
||||
PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
|
||||
ssize);
|
||||
return NULL;
|
||||
PyErr_Format(PyExc_ValueError, "expected sample size >= 0, not %d",
|
||||
ssize);
|
||||
return NULL;
|
||||
}
|
||||
if (nchannels != 1 && nchannels != 2) {
|
||||
PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
|
||||
nchannels);
|
||||
return NULL;
|
||||
PyErr_Format(PyExc_ValueError, "nchannels must be 1 or 2, not %d",
|
||||
nchannels);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (n = 0; n < n_audio_types; n++)
|
||||
if (fmt == audio_types[n].a_fmt)
|
||||
break;
|
||||
if (n == n_audio_types) {
|
||||
PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
|
||||
return NULL;
|
||||
PyErr_Format(PyExc_ValueError, "unknown audio encoding: %d", fmt);
|
||||
return NULL;
|
||||
}
|
||||
if (audio_types[n].a_bps != ssize) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"for %s, expected sample size %d, not %d",
|
||||
audio_types[n].a_name, audio_types[n].a_bps, ssize);
|
||||
return NULL;
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"for %s, expected sample size %d, not %d",
|
||||
audio_types[n].a_name, audio_types[n].a_bps, ssize);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (emulate == 0) {
|
||||
if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s format not supported by device",
|
||||
audio_types[n].a_name);
|
||||
return NULL;
|
||||
}
|
||||
if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s format not supported by device",
|
||||
audio_types[n].a_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
|
||||
&audio_types[n].a_fmt) == -1) {
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
|
||||
&audio_types[n].a_fmt) == -1) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ _ssize(lad_t *self, int *nchannels, int *ssize)
|
|||
int fmt;
|
||||
|
||||
fmt = 0;
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
|
||||
if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
|
||||
return -errno;
|
||||
|
||||
switch (fmt) {
|
||||
|
@ -334,7 +334,7 @@ _ssize(lad_t *self, int *nchannels, int *ssize)
|
|||
}
|
||||
|
||||
|
||||
/* 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 *
|
||||
lad_bufsize(lad_t *self, PyObject *unused)
|
||||
|
@ -353,7 +353,7 @@ lad_bufsize(lad_t *self, PyObject *unused)
|
|||
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 *
|
||||
lad_obufcount(lad_t *self, PyObject *unused)
|
||||
|
@ -369,7 +369,7 @@ lad_obufcount(lad_t *self, PyObject *unused)
|
|||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
}
|
||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
|
||||
return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
|
||||
(ssize * nchannels));
|
||||
}
|
||||
|
||||
|
@ -410,9 +410,9 @@ lad_getptr(lad_t *self, PyObject *unused)
|
|||
int req;
|
||||
|
||||
if (self->x_mode == O_RDONLY)
|
||||
req = SNDCTL_DSP_GETIPTR;
|
||||
req = SNDCTL_DSP_GETIPTR;
|
||||
else
|
||||
req = SNDCTL_DSP_GETOPTR;
|
||||
req = SNDCTL_DSP_GETOPTR;
|
||||
if (ioctl(self->x_fd, req, &info) == -1) {
|
||||
PyErr_SetFromErrno(LinuxAudioError);
|
||||
return NULL;
|
||||
|
@ -421,17 +421,17 @@ lad_getptr(lad_t *self, PyObject *unused)
|
|||
}
|
||||
|
||||
static PyMethodDef lad_methods[] = {
|
||||
{ "read", (PyCFunction)lad_read, METH_VARARGS },
|
||||
{ "write", (PyCFunction)lad_write, METH_VARARGS },
|
||||
{ "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS },
|
||||
{ "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS },
|
||||
{ "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS },
|
||||
{ "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS },
|
||||
{ "flush", (PyCFunction)lad_flush, METH_NOARGS },
|
||||
{ "close", (PyCFunction)lad_close, METH_NOARGS },
|
||||
{ "fileno", (PyCFunction)lad_fileno, METH_NOARGS },
|
||||
{ "read", (PyCFunction)lad_read, METH_VARARGS },
|
||||
{ "write", (PyCFunction)lad_write, METH_VARARGS },
|
||||
{ "setparameters", (PyCFunction)lad_setparameters, METH_VARARGS },
|
||||
{ "bufsize", (PyCFunction)lad_bufsize, METH_VARARGS },
|
||||
{ "obufcount", (PyCFunction)lad_obufcount, METH_NOARGS },
|
||||
{ "obuffree", (PyCFunction)lad_obuffree, METH_NOARGS },
|
||||
{ "flush", (PyCFunction)lad_flush, METH_NOARGS },
|
||||
{ "close", (PyCFunction)lad_close, METH_NOARGS },
|
||||
{ "fileno", (PyCFunction)lad_fileno, METH_NOARGS },
|
||||
{ "getptr", (PyCFunction)lad_getptr, METH_NOARGS },
|
||||
{ NULL, NULL} /* sentinel */
|
||||
{ NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
|
@ -443,15 +443,15 @@ lad_getattr(lad_t *xp, char *name)
|
|||
static PyTypeObject Ladtype = {
|
||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||
"linuxaudiodev.linux_audio_device", /*tp_name*/
|
||||
sizeof(lad_t), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
sizeof(lad_t), /*tp_size*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor)lad_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)lad_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
(destructor)lad_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc)lad_getattr, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
|
@ -469,37 +469,37 @@ void
|
|||
initlinuxaudiodev(void)
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
|
||||
if (PyErr_WarnPy3k("the linuxaudiodev module has been removed in "
|
||||
"Python 3.0; use the ossaudiodev module instead", 2) < 0)
|
||||
return;
|
||||
|
||||
|
||||
m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
|
||||
if (m == NULL)
|
||||
return;
|
||||
return;
|
||||
|
||||
LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
|
||||
if (LinuxAudioError)
|
||||
PyModule_AddObject(m, "error", LinuxAudioError);
|
||||
PyModule_AddObject(m, "error", LinuxAudioError);
|
||||
|
||||
if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1)
|
||||
return;
|
||||
return;
|
||||
if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1)
|
||||
return;
|
||||
return;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue