summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/Setup.dist11
-rw-r--r--Modules/_csv.c6
-rw-r--r--Modules/_hotshot.c2
-rw-r--r--Modules/bz2module.c2
-rw-r--r--Modules/linuxaudiodev.c501
-rw-r--r--Modules/sunaudiodev.c463
6 files changed, 5 insertions, 980 deletions
diff --git a/Modules/Setup.dist b/Modules/Setup.dist
index 4ea727f..86b8f84 100644
--- a/Modules/Setup.dist
+++ b/Modules/Setup.dist
@@ -236,17 +236,6 @@ _symtable symtablemodule.c
#_sha shamodule.c
-# SunOS specific modules -- off by default:
-
-#sunaudiodev sunaudiodev.c
-
-
-# A Linux specific module -- off by default; this may also work on
-# some *BSDs.
-
-#linuxaudiodev linuxaudiodev.c
-
-
# The _tkinter module.
#
# The command for _tkinter is long and site specific. Please
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 246cc6c..d12aa4f 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -861,8 +861,8 @@ static struct PyMethodDef Reader_methods[] = {
#define R_OFF(x) offsetof(ReaderObj, x)
static struct PyMemberDef Reader_memberlist[] = {
- { "dialect", T_OBJECT, R_OFF(dialect), RO },
- { "line_num", T_ULONG, R_OFF(line_num), RO },
+ { "dialect", T_OBJECT, R_OFF(dialect), READONLY },
+ { "line_num", T_ULONG, R_OFF(line_num), READONLY },
{ NULL }
};
@@ -1239,7 +1239,7 @@ static struct PyMethodDef Writer_methods[] = {
#define W_OFF(x) offsetof(WriterObj, x)
static struct PyMemberDef Writer_memberlist[] = {
- { "dialect", T_OBJECT, W_OFF(dialect), RO },
+ { "dialect", T_OBJECT, W_OFF(dialect), READONLY },
{ NULL }
};
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index dff78c7..b34c543 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -1266,7 +1266,7 @@ static PyMethodDef logreader_methods[] = {
};
static PyMemberDef logreader_members[] = {
- {"info", T_OBJECT, offsetof(LogReaderObject, info), RO,
+ {"info", T_OBJECT, offsetof(LogReaderObject, info), READONLY,
PyDoc_STR("Dictionary mapping informational keys to lists of values.")},
{NULL}
};
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 43c287b..ee2186e 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -1624,7 +1624,7 @@ static PyTypeObject BZ2Comp_Type = {
#define OFF(x) offsetof(BZ2DecompObject, x)
static PyMemberDef BZ2Decomp_members[] = {
- {"unused_data", T_OBJECT, OFF(unused_data), RO},
+ {"unused_data", T_OBJECT, OFF(unused_data), READONLY},
{NULL} /* Sentinel */
};
diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c
deleted file mode 100644
index 730ec0c..0000000
--- a/Modules/linuxaudiodev.c
+++ /dev/null
@@ -1,501 +0,0 @@
-/* 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
- * (C) 2000 Peter Bosch, all rights reserved.
- ******************************************************************************
- */
-
-#include "Python.h"
-#include "structmember.h"
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#else
-#define O_RDONLY 00
-#define O_WRONLY 01
-#endif
-
-
-#include <sys/ioctl.h>
-#if defined(linux)
-#include <linux/soundcard.h>
-
-#ifndef HAVE_STDINT_H
-typedef unsigned long uint32_t;
-#endif
-
-#elif defined(__FreeBSD__)
-#include <machine/soundcard.h>
-
-#ifndef SNDCTL_DSP_CHANNELS
-#define SNDCTL_DSP_CHANNELS SOUND_PCM_WRITE_CHANNELS
-#endif
-
-#endif
-
-typedef struct {
- PyObject_HEAD
- 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*/
-} lad_t;
-
-/* XXX several format defined in soundcard.h are not supported,
- including _NE (native endian) options and S32 options
-*/
-
-static struct {
- 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" },
-};
-
-static int n_audio_types = sizeof(audio_types) / sizeof(audio_types[0]);
-
-static PyTypeObject Ladtype;
-
-static PyObject *LinuxAudioError;
-
-static lad_t *
-newladobject(PyObject *arg)
-{
- lad_t *xp;
- int fd, afmts, imode;
- char *basedev = NULL;
- char *mode = NULL;
-
- /* Two ways to call linuxaudiodev.open():
- open(device, mode) (for consistency with builtin open())
- open(mode) (for backwards compatibility)
- because the *first* argument is optional, parsing args is
- a wee bit tricky. */
- if (!PyArg_ParseTuple(arg, "s|s:open", &basedev, &mode))
- return NULL;
- if (mode == NULL) { /* only one arg supplied */
- mode = basedev;
- basedev = NULL;
- }
-
- if (strcmp(mode, "r") == 0)
- imode = O_RDONLY;
- else if (strcmp(mode, "w") == 0)
- imode = O_WRONLY;
- else {
- PyErr_SetString(LinuxAudioError, "mode should be 'r' or 'w'");
- return NULL;
- }
-
- /* 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.
- */
-
- if (basedev == NULL) { /* called with one arg */
- basedev = getenv("AUDIODEV");
- if (basedev == NULL) /* $AUDIODEV not set */
- basedev = "/dev/dsp";
- }
-
- if ((fd = open(basedev, imode)) == -1) {
- PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
- return NULL;
- }
- if (imode == O_WRONLY && ioctl(fd, SNDCTL_DSP_NONBLOCK, NULL) == -1) {
- PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
- return NULL;
- }
- if (ioctl(fd, SNDCTL_DSP_GETFMTS, &afmts) == -1) {
- PyErr_SetFromErrnoWithFilename(LinuxAudioError, basedev);
- return NULL;
- }
- /* Create and initialize the object */
- if ((xp = PyObject_New(lad_t, &Ladtype)) == NULL) {
- close(fd);
- return NULL;
- }
- xp->x_fd = fd;
- xp->x_mode = imode;
- xp->x_icount = xp->x_ocount = 0;
- xp->x_afmts = afmts;
- return xp;
-}
-
-static void
-lad_dealloc(lad_t *xp)
-{
- /* if already closed, don't reclose it */
- if (xp->x_fd != -1)
- close(xp->x_fd);
- PyObject_Del(xp);
-}
-
-static PyObject *
-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);
- if (rv == NULL)
- return NULL;
- cp = PyString_AS_STRING(rv);
- if ((count = read(self->x_fd, cp, size)) < 0) {
- PyErr_SetFromErrno(LinuxAudioError);
- Py_DECREF(rv);
- return NULL;
- }
- self->x_icount += count;
- _PyString_Resize(&rv, count);
- return rv;
-}
-
-static PyObject *
-lad_write(lad_t *self, PyObject *args)
-{
- char *cp;
- int rv, size;
- fd_set write_set_fds;
- struct timeval tv;
- int select_retval;
-
- 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;
-
- 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 */
- }
- } else {
- 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;
- }
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-lad_close(lad_t *self, PyObject *unused)
-{
- if (self->x_fd >= 0) {
- close(self->x_fd);
- self->x_fd = -1;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *
-lad_fileno(lad_t *self, PyObject *unused)
-{
- return PyInt_FromLong(self->x_fd);
-}
-
-static PyObject *
-lad_setparameters(lad_t *self, PyObject *args)
-{
- int rate, ssize, nchannels, n, fmt, emulate=0;
-
- 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;
- }
- if (ssize < 0) {
- 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;
- }
-
- 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;
- }
- 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;
- }
-
- 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 (ioctl(self->x_fd, SNDCTL_DSP_SETFMT,
- &audio_types[n].a_fmt) == -1) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static int
-_ssize(lad_t *self, int *nchannels, int *ssize)
-{
- int fmt;
-
- fmt = 0;
- if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
- return -errno;
-
- switch (fmt) {
- case AFMT_MU_LAW:
- case AFMT_A_LAW:
- case AFMT_U8:
- case AFMT_S8:
- *ssize = sizeof(char);
- break;
- case AFMT_S16_LE:
- case AFMT_S16_BE:
- case AFMT_U16_LE:
- case AFMT_U16_BE:
- *ssize = sizeof(short);
- break;
- case AFMT_MPEG:
- case AFMT_IMA_ADPCM:
- default:
- return -EOPNOTSUPP;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
- return -errno;
- return 0;
-}
-
-
-/* bufsize returns the size of the hardware audio buffer in number
- of samples */
-static PyObject *
-lad_bufsize(lad_t *self, PyObject *unused)
-{
- audio_buf_info ai;
- int nchannels=0, ssize=0;
-
- if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- return PyInt_FromLong((ai.fragstotal * ai.fragsize) / (nchannels * ssize));
-}
-
-/* obufcount returns the number of samples that are available in the
- hardware for playing */
-static PyObject *
-lad_obufcount(lad_t *self, PyObject *unused)
-{
- audio_buf_info ai;
- int nchannels=0, ssize=0;
-
- if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- return PyInt_FromLong((ai.fragstotal * ai.fragsize - ai.bytes) /
- (ssize * nchannels));
-}
-
-/* obufcount returns the number of samples that can be played without
- blocking */
-static PyObject *
-lad_obuffree(lad_t *self, PyObject *unused)
-{
- audio_buf_info ai;
- int nchannels=0, ssize=0;
-
- if (_ssize(self, &nchannels, &ssize) < 0 || !ssize || !nchannels) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- return PyInt_FromLong(ai.bytes / (ssize * nchannels));
-}
-
-/* Flush the device */
-static PyObject *
-lad_flush(lad_t *self, PyObject *unused)
-{
- if (ioctl(self->x_fd, SNDCTL_DSP_SYNC, NULL) == -1) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *
-lad_getptr(lad_t *self, PyObject *unused)
-{
- count_info info;
- int req;
-
- if (self->x_mode == O_RDONLY)
- req = SNDCTL_DSP_GETIPTR;
- else
- req = SNDCTL_DSP_GETOPTR;
- if (ioctl(self->x_fd, req, &info) == -1) {
- PyErr_SetFromErrno(LinuxAudioError);
- return NULL;
- }
- return Py_BuildValue("iii", info.bytes, info.blocks, info.ptr);
-}
-
-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 },
- { "getptr", (PyCFunction)lad_getptr, METH_NOARGS },
- { NULL, NULL} /* sentinel */
-};
-
-static PyObject *
-lad_getattr(lad_t *xp, char *name)
-{
- return Py_FindMethod(lad_methods, (PyObject *)xp, name);
-}
-
-static PyTypeObject Ladtype = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "linuxaudiodev.linux_audio_device", /*tp_name*/
- 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*/
-};
-
-static PyObject *
-ladopen(PyObject *self, PyObject *args)
-{
- return (PyObject *)newladobject(args);
-}
-
-static PyMethodDef linuxaudiodev_methods[] = {
- { "open", ladopen, METH_VARARGS },
- { 0, 0 },
-};
-
-void
-initlinuxaudiodev(void)
-{
- PyObject *m;
-
- m = Py_InitModule("linuxaudiodev", linuxaudiodev_methods);
- if (m == NULL)
- return;
-
- LinuxAudioError = PyErr_NewException("linuxaudiodev.error", NULL, NULL);
- if (LinuxAudioError)
- PyModule_AddObject(m, "error", LinuxAudioError);
-
- if (PyModule_AddIntConstant(m, "AFMT_MU_LAW", (long)AFMT_MU_LAW) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_A_LAW", (long)AFMT_A_LAW) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_U8", (long)AFMT_U8) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_S8", (long)AFMT_S8) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_U16_BE", (long)AFMT_U16_BE) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_U16_LE", (long)AFMT_U16_LE) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_S16_BE", (long)AFMT_S16_BE) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_S16_LE", (long)AFMT_S16_LE) == -1)
- return;
- if (PyModule_AddIntConstant(m, "AFMT_S16_NE", (long)AFMT_S16_NE) == -1)
- return;
-
- return;
-}
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
deleted file mode 100644
index 4288403..0000000
--- a/Modules/sunaudiodev.c
+++ /dev/null
@@ -1,463 +0,0 @@
-
-/* Sad objects */
-
-#include "Python.h"
-#include "structmember.h"
-
-#ifdef HAVE_SYS_AUDIOIO_H
-#define SOLARIS
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#include <stropts.h>
-#include <sys/ioctl.h>
-#ifdef SOLARIS
-#include <sys/audioio.h>
-#else
-#include <sun/audioio.h>
-#endif
-
-/* #define offsetof(str,mem) ((int)(((str *)0)->mem)) */
-
-typedef struct {
- PyObject_HEAD
- int x_fd; /* The open file */
- int x_icount; /* # samples read */
- int x_ocount; /* # samples written */
- int x_isctl; /* True if control device */
-
-} sadobject;
-
-typedef struct {
- PyObject_HEAD
- audio_info_t ai;
-} sadstatusobject;
-
-static PyTypeObject Sadtype;
-static PyTypeObject Sadstatustype;
-static sadstatusobject *sads_alloc(void); /* Forward */
-
-static PyObject *SunAudioError;
-
-#define is_sadobject(v) (Py_Type(v) == &Sadtype)
-#define is_sadstatusobject(v) (Py_Type(v) == &Sadstatustype)
-
-
-static sadobject *
-newsadobject(PyObject *args)
-{
- sadobject *xp;
- int fd;
- char *mode;
- int imode;
- char* basedev;
- char* ctldev;
- char* opendev;
-
- /* Check arg for r/w/rw */
- if (!PyArg_ParseTuple(args, "s", &mode))
- return NULL;
- if (strcmp(mode, "r") == 0)
- imode = 0;
- else if (strcmp(mode, "w") == 0)
- imode = 1;
- else if (strcmp(mode, "rw") == 0)
- imode = 2;
- else if (strcmp(mode, "control") == 0)
- imode = -1;
- else {
- PyErr_SetString(SunAudioError,
- "Mode should be one of 'r', 'w', 'rw' or 'control'");
- return NULL;
- }
-
- /* Open the correct device. The base device name comes from the
- * AUDIODEV environment variable first, then /dev/audio. The
- * control device tacks "ctl" onto the base device name.
- */
- basedev = getenv("AUDIODEV");
- if (!basedev)
- basedev = "/dev/audio";
- ctldev = PyMem_NEW(char, strlen(basedev) + 4);
- if (!ctldev) {
- PyErr_NoMemory();
- return NULL;
- }
- strcpy(ctldev, basedev);
- strcat(ctldev, "ctl");
-
- if (imode < 0) {
- opendev = ctldev;
- fd = open(ctldev, 2);
- }
- else {
- opendev = basedev;
- fd = open(basedev, imode);
- }
- if (fd < 0) {
- PyErr_SetFromErrnoWithFilename(SunAudioError, opendev);
- PyMem_DEL(ctldev);
- return NULL;
- }
- PyMem_DEL(ctldev);
-
- /* Create and initialize the object */
- xp = PyObject_New(sadobject, &Sadtype);
- if (xp == NULL) {
- close(fd);
- return NULL;
- }
- xp->x_fd = fd;
- xp->x_icount = xp->x_ocount = 0;
- xp->x_isctl = (imode < 0);
-
- return xp;
-}
-
-/* Sad methods */
-
-static void
-sad_dealloc(sadobject *xp)
-{
- close(xp->x_fd);
- PyObject_Del(xp);
-}
-
-static PyObject *
-sad_read(sadobject *self, PyObject *args)
-{
- int size, count;
- char *cp;
- PyObject *rv;
-
- if (!PyArg_ParseTuple(args, "i:read", &size))
- return NULL;
- rv = PyString_FromStringAndSize(NULL, size);
- if (rv == NULL)
- return NULL;
-
- if (!(cp = PyString_AsString(rv)))
- goto finally;
-
- count = read(self->x_fd, cp, size);
- if (count < 0) {
- PyErr_SetFromErrno(SunAudioError);
- goto finally;
- }
-#if 0
- /* TBD: why print this message if you can handle the condition?
- * assume it's debugging info which we can just as well get rid
- * of. in any case this message should *not* be using printf!
- */
- if (count != size)
- printf("sunaudio: funny read rv %d wtd %d\n", count, size);
-#endif
- self->x_icount += count;
- return rv;
-
- finally:
- Py_DECREF(rv);
- return NULL;
-}
-
-static PyObject *
-sad_write(sadobject *self, PyObject *args)
-{
- char *cp;
- int count, size;
-
- if (!PyArg_ParseTuple(args, "s#:write", &cp, &size))
- return NULL;
-
- count = write(self->x_fd, cp, size);
- if (count < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
-#if 0
- if (count != size)
- printf("sunaudio: funny write rv %d wanted %d\n", count, size);
-#endif
- self->x_ocount += count;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-sad_getinfo(sadobject *self)
-{
- sadstatusobject *rv;
-
- if (!(rv = sads_alloc()))
- return NULL;
-
- if (ioctl(self->x_fd, AUDIO_GETINFO, &rv->ai) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- Py_DECREF(rv);
- return NULL;
- }
- return (PyObject *)rv;
-}
-
-static PyObject *
-sad_setinfo(sadobject *self, sadstatusobject *arg)
-{
- if (!is_sadstatusobject(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "Must be sun audio status object");
- return NULL;
- }
- if (ioctl(self->x_fd, AUDIO_SETINFO, &arg->ai) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-sad_ibufcount(sadobject *self)
-{
- audio_info_t ai;
-
- if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- return PyInt_FromLong(ai.record.samples - self->x_icount);
-}
-
-static PyObject *
-sad_obufcount(sadobject *self)
-{
- audio_info_t ai;
-
- if (ioctl(self->x_fd, AUDIO_GETINFO, &ai) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- /* x_ocount is in bytes, whereas play.samples is in frames */
- /* we want frames */
- return PyInt_FromLong(self->x_ocount / (ai.play.channels *
- ai.play.precision / 8) -
- ai.play.samples);
-}
-
-static PyObject *
-sad_drain(sadobject *self)
-{
- if (ioctl(self->x_fd, AUDIO_DRAIN, 0) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-#ifdef SOLARIS
-static PyObject *
-sad_getdev(sadobject *self)
-{
- struct audio_device ad;
-
- if (ioctl(self->x_fd, AUDIO_GETDEV, &ad) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- return Py_BuildValue("(sss)", ad.name, ad.version, ad.config);
-}
-#endif
-
-static PyObject *
-sad_flush(sadobject *self)
-{
- if (ioctl(self->x_fd, I_FLUSH, FLUSHW) < 0) {
- PyErr_SetFromErrno(SunAudioError);
- return NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-sad_close(sadobject *self)
-{
-
- if (self->x_fd >= 0) {
- close(self->x_fd);
- self->x_fd = -1;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static PyObject *
-sad_fileno(sadobject *self)
-{
- return PyInt_FromLong(self->x_fd);
-}
-
-
-static PyMethodDef sad_methods[] = {
- { "read", (PyCFunction)sad_read, METH_VARARGS },
- { "write", (PyCFunction)sad_write, METH_VARARGS },
- { "ibufcount", (PyCFunction)sad_ibufcount, METH_NOARGS },
- { "obufcount", (PyCFunction)sad_obufcount, METH_NOARGS },
-#define CTL_METHODS 4
- { "getinfo", (PyCFunction)sad_getinfo, METH_NOARGS },
- { "setinfo", (PyCFunction)sad_setinfo, METH_O},
- { "drain", (PyCFunction)sad_drain, METH_NOARGS },
- { "flush", (PyCFunction)sad_flush, METH_NOARGS },
-#ifdef SOLARIS
- { "getdev", (PyCFunction)sad_getdev, METH_NOARGS },
-#endif
- { "close", (PyCFunction)sad_close, METH_NOARGS },
- { "fileno", (PyCFunction)sad_fileno, METH_NOARGS },
- {NULL, NULL} /* sentinel */
-};
-
-static PyObject *
-sad_getattr(sadobject *xp, char *name)
-{
- if (xp->x_isctl)
- return Py_FindMethod(sad_methods+CTL_METHODS,
- (PyObject *)xp, name);
- else
- return Py_FindMethod(sad_methods, (PyObject *)xp, name);
-}
-
-/* ----------------------------------------------------------------- */
-
-static sadstatusobject *
-sads_alloc(void) {
- return PyObject_New(sadstatusobject, &Sadstatustype);
-}
-
-static void
-sads_dealloc(sadstatusobject *xp)
-{
- PyMem_DEL(xp);
-}
-
-#define OFF(x) offsetof(audio_info_t,x)
-static struct memberlist sads_ml[] = {
- { "i_sample_rate", T_UINT, OFF(record.sample_rate) },
- { "i_channels", T_UINT, OFF(record.channels) },
- { "i_precision", T_UINT, OFF(record.precision) },
- { "i_encoding", T_UINT, OFF(record.encoding) },
- { "i_gain", T_UINT, OFF(record.gain) },
- { "i_port", T_UINT, OFF(record.port) },
- { "i_samples", T_UINT, OFF(record.samples) },
- { "i_eof", T_UINT, OFF(record.eof) },
- { "i_pause", T_UBYTE, OFF(record.pause) },
- { "i_error", T_UBYTE, OFF(record.error) },
- { "i_waiting", T_UBYTE, OFF(record.waiting) },
- { "i_open", T_UBYTE, OFF(record.open) , RO},
- { "i_active", T_UBYTE, OFF(record.active) , RO},
-#ifdef SOLARIS
- { "i_buffer_size", T_UINT, OFF(record.buffer_size) },
- { "i_balance", T_UBYTE, OFF(record.balance) },
- { "i_avail_ports", T_UINT, OFF(record.avail_ports) },
-#endif
-
- { "o_sample_rate", T_UINT, OFF(play.sample_rate) },
- { "o_channels", T_UINT, OFF(play.channels) },
- { "o_precision", T_UINT, OFF(play.precision) },
- { "o_encoding", T_UINT, OFF(play.encoding) },
- { "o_gain", T_UINT, OFF(play.gain) },
- { "o_port", T_UINT, OFF(play.port) },
- { "o_samples", T_UINT, OFF(play.samples) },
- { "o_eof", T_UINT, OFF(play.eof) },
- { "o_pause", T_UBYTE, OFF(play.pause) },
- { "o_error", T_UBYTE, OFF(play.error) },
- { "o_waiting", T_UBYTE, OFF(play.waiting) },
- { "o_open", T_UBYTE, OFF(play.open) , RO},
- { "o_active", T_UBYTE, OFF(play.active) , RO},
-#ifdef SOLARIS
- { "o_buffer_size", T_UINT, OFF(play.buffer_size) },
- { "o_balance", T_UBYTE, OFF(play.balance) },
- { "o_avail_ports", T_UINT, OFF(play.avail_ports) },
-#endif
-
- { "monitor_gain", T_UINT, OFF(monitor_gain) },
- { NULL, 0, 0},
-};
-
-static PyObject *
-sads_getattr(sadstatusobject *xp, char *name)
-{
- return PyMember_Get((char *)&xp->ai, sads_ml, name);
-}
-
-static int
-sads_setattr(sadstatusobject *xp, char *name, PyObject *v)
-{
-
- if (v == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "can't delete sun audio status attributes");
- return -1;
- }
- return PyMember_Set((char *)&xp->ai, sads_ml, name, v);
-}
-
-/* ------------------------------------------------------------------- */
-
-
-static PyTypeObject Sadtype = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "sunaudiodev.sun_audio_device", /*tp_name*/
- sizeof(sadobject), /*tp_size*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)sad_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)sad_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
-};
-
-static PyTypeObject Sadstatustype = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "sunaudiodev.sun_audio_device_status", /*tp_name*/
- sizeof(sadstatusobject), /*tp_size*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)sads_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)sads_getattr, /*tp_getattr*/
- (setattrfunc)sads_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
-};
-/* ------------------------------------------------------------------- */
-
-static PyObject *
-sadopen(PyObject *self, PyObject *args)
-{
- return (PyObject *)newsadobject(args);
-}
-
-static PyMethodDef sunaudiodev_methods[] = {
- { "open", sadopen, METH_VARARGS },
- { 0, 0 },
-};
-
-void
-initsunaudiodev(void)
-{
- PyObject *m, *d;
-
- m = Py_InitModule("sunaudiodev", sunaudiodev_methods);
- if (m == NULL)
- return;
- d = PyModule_GetDict(m);
- SunAudioError = PyErr_NewException("sunaudiodev.error", NULL, NULL);
- if (SunAudioError)
- PyDict_SetItemString(d, "error", SunAudioError);
-}