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*/
+ int fd; /* The open file */
+ int mode; /* file mode */
+ int icount; /* Input count */
+ int ocount; /* Output count */
+ uint32_t afmts; /* Audio formats supported by hardware */
} oss_t;
typedef struct {
PyObject_HEAD;
- int x_fd; /* The open mixer device */
+ int fd; /* The open mixer device */
} oss_mixer_t;
/* XXX several format defined in soundcard.h are not supported,
close(fd);
return NULL;
}
- xp->x_fd = fd;
- xp->x_mode = imode;
- xp->x_icount = xp->x_ocount = 0;
- xp->x_afmts = afmts;
+ xp->fd = fd;
+ xp->mode = imode;
+ xp->icount = xp->ocount = 0;
+ xp->afmts = afmts;
return xp;
}
oss_dealloc(oss_t *xp)
{
/* if already closed, don't reclose it */
- if (xp->x_fd != -1)
- close(xp->x_fd);
+ if (xp->fd != -1)
+ close(xp->fd);
PyObject_Del(xp);
}
return NULL;
}
- xp->x_fd = fd;
+ xp->fd = fd;
return xp;
}
oss_mixer_dealloc(oss_mixer_t *xp)
{
/* if already closed, don't reclose it */
- if (xp->x_fd != -1)
- close(xp->x_fd);
+ if (xp->fd != -1)
+ close(xp->fd);
PyObject_Del(xp);
}
mode once we're in non-blocking mode! */
if (!PyArg_ParseTuple(args, ":nonblock"))
return NULL;
- if (ioctl(self->x_fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
+ if (ioctl(self->fd, SNDCTL_DSP_NONBLOCK, NULL) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
Py_INCREF(Py_None);
return Py_None;
static PyObject *
oss_setfmt(oss_t *self, PyObject *args)
{
- return _do_ioctl_1(self->x_fd, args, "setfmt", SNDCTL_DSP_SETFMT);
+ return _do_ioctl_1(self->fd, args, "setfmt", SNDCTL_DSP_SETFMT);
}
static PyObject *
int mask;
if (!PyArg_ParseTuple(args, ":getfmts"))
return NULL;
- if (ioctl(self->x_fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
+ if (ioctl(self->fd, SNDCTL_DSP_GETFMTS, &mask) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return PyInt_FromLong(mask);
}
static PyObject *
oss_channels(oss_t *self, PyObject *args)
{
- return _do_ioctl_1(self->x_fd, args, "channels", SNDCTL_DSP_CHANNELS);
+ return _do_ioctl_1(self->fd, args, "channels", SNDCTL_DSP_CHANNELS);
}
static PyObject *
oss_speed(oss_t *self, PyObject *args)
{
- return _do_ioctl_1(self->x_fd, args, "speed", SNDCTL_DSP_SPEED);
+ return _do_ioctl_1(self->fd, args, "speed", SNDCTL_DSP_SPEED);
}
static PyObject *
oss_sync(oss_t *self, PyObject *args)
{
- return _do_ioctl_0(self->x_fd, args, "sync", SNDCTL_DSP_SYNC);
+ return _do_ioctl_0(self->fd, args, "sync", SNDCTL_DSP_SYNC);
}
static PyObject *
oss_reset(oss_t *self, PyObject *args)
{
- return _do_ioctl_0(self->x_fd, args, "reset", SNDCTL_DSP_RESET);
+ return _do_ioctl_0(self->fd, args, "reset", SNDCTL_DSP_RESET);
}
static PyObject *
oss_post(oss_t *self, PyObject *args)
{
- return _do_ioctl_0(self->x_fd, args, "post", SNDCTL_DSP_POST);
+ return _do_ioctl_0(self->fd, args, "post", SNDCTL_DSP_POST);
}
if (rv == NULL)
return NULL;
cp = PyString_AS_STRING(rv);
- if ((count = read(self->x_fd, cp, size)) < 0) {
+ if ((count = read(self->fd, cp, size)) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
Py_DECREF(rv);
return NULL;
}
- self->x_icount += count;
+ self->icount += count;
_PyString_Resize(&rv, count);
return rv;
}
if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
return NULL;
}
- if ((rv = write(self->x_fd, cp, size)) == -1) {
+ if ((rv = write(self->fd, cp, size)) == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
} else {
- self->x_ocount += rv;
+ self->ocount += rv;
}
return PyInt_FromLong(rv);
}
/* use select to wait for audio device to be available */
FD_ZERO(&write_set_fds);
- FD_SET(self->x_fd, &write_set_fds);
+ FD_SET(self->fd, &write_set_fds);
while (size > 0) {
- select_rv = select(self->x_fd+1, NULL, &write_set_fds, NULL, NULL);
+ select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
assert(select_rv != 0); /* no timeout, can't expire */
if (select_rv == -1)
return PyErr_SetFromErrno(PyExc_IOError);
- rv = write(self->x_fd, cp, size);
+ rv = write(self->fd, cp, size);
if (rv == -1) {
if (errno == EAGAIN) { /* buffer is full, try again */
errno = 0;
} else /* it's a real error */
return PyErr_SetFromErrno(PyExc_IOError);
} else { /* wrote rv bytes */
- self->x_ocount += rv;
+ self->ocount += rv;
size -= rv;
cp += rv;
}
if (!PyArg_ParseTuple(args, ":close"))
return NULL;
- if (self->x_fd >= 0) {
- close(self->x_fd);
- self->x_fd = -1;
+ if (self->fd >= 0) {
+ close(self->fd);
+ self->fd = -1;
}
Py_INCREF(Py_None);
return Py_None;
{
if (!PyArg_ParseTuple(args, ":fileno"))
return NULL;
- return PyInt_FromLong(self->x_fd);
+ return PyInt_FromLong(self->fd);
}
}
if (emulate == 0) {
- if ((self->x_afmts & audio_types[n].a_fmt) == 0) {
+ if ((self->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,
+ if (ioctl(self->fd, SNDCTL_DSP_SETFMT,
&audio_types[n].a_fmt) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
+ if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, &nchannels) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- if (ioctl(self->x_fd, SNDCTL_DSP_SPEED, &rate) == -1) {
+ if (ioctl(self->fd, SNDCTL_DSP_SPEED, &rate) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
int fmt;
fmt = 0;
- if (ioctl(self->x_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
+ if (ioctl(self->fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
return -errno;
switch (fmt) {
return -EOPNOTSUPP;
}
*nchannels = 0;
- if (ioctl(self->x_fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
+ if (ioctl(self->fd, SNDCTL_DSP_CHANNELS, nchannels) < 0)
return -errno;
return 0;
}
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
+ if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
+ if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- if (ioctl(self->x_fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
+ if (ioctl(self->fd, SNDCTL_DSP_GETOSPACE, &ai) < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
if (!PyArg_ParseTuple(args, ":getptr"))
return NULL;
- if (self->x_mode == O_RDONLY)
+ if (self->mode == O_RDONLY)
req = SNDCTL_DSP_GETIPTR;
else
req = SNDCTL_DSP_GETOPTR;
- if (ioctl(self->x_fd, req, &info) == -1) {
+ if (ioctl(self->fd, req, &info) == -1) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
if (!PyArg_ParseTuple(args, ":close"))
return NULL;
- if (self->x_fd >= 0) {
- close(self->x_fd);
- self->x_fd = -1;
+ if (self->fd >= 0) {
+ close(self->fd);
+ self->fd = -1;
}
Py_INCREF(Py_None);
return Py_None;
{
if (!PyArg_ParseTuple(args, ":fileno"))
return NULL;
- return PyInt_FromLong(self->x_fd);
+ return PyInt_FromLong(self->fd);
}
/* Simple mixer interface methods */
static PyObject *
oss_mixer_channels (oss_mixer_t *self, PyObject *args)
{
- return _do_ioctl_1_internal(self->x_fd, args, "channels",
+ return _do_ioctl_1_internal(self->fd, args, "channels",
SOUND_MIXER_READ_DEVMASK);
}
static PyObject *
oss_mixer_stereo_channels (oss_mixer_t *self, PyObject *args)
{
- return _do_ioctl_1_internal(self->x_fd, args, "stereochannels",
+ return _do_ioctl_1_internal(self->fd, args, "stereochannels",
SOUND_MIXER_READ_STEREODEVS);
}
static PyObject *
oss_mixer_rec_channels (oss_mixer_t *self, PyObject *args)
{
- return _do_ioctl_1_internal(self->x_fd, args, "recchannels",
+ return _do_ioctl_1_internal(self->fd, args, "recchannels",
SOUND_MIXER_READ_RECMASK);
}
return NULL;
}
- if (ioctl (self->x_fd, MIXER_READ(channel), &volume) == -1)
+ if (ioctl (self->fd, MIXER_READ(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return Py_BuildValue ("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
volume = (rightVol << 8) | leftVol;
- if (ioctl (self->x_fd, MIXER_WRITE(channel), &volume) == -1)
+ if (ioctl (self->fd, MIXER_WRITE(channel), &volume) == -1)
return PyErr_SetFromErrno(PyExc_IOError);
return Py_BuildValue ("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
static PyObject *
oss_mixer_getrecsrc (oss_mixer_t *self, PyObject *args)
{
- return _do_ioctl_1_internal(self->x_fd, args, "getrecsrc",
+ return _do_ioctl_1_internal(self->fd, args, "getrecsrc",
SOUND_MIXER_READ_RECSRC);
}
static PyObject *
oss_mixer_setrecsrc (oss_mixer_t *self, PyObject *args)
{
- return _do_ioctl_1(self->x_fd, args, "setrecsrc",
+ return _do_ioctl_1(self->fd, args, "setrecsrc",
SOUND_MIXER_WRITE_RECSRC);
}
_EXPORT_INT(m, AFMT_S16_NE);
/* Expose the sound mixer channels. */
+ _EXPORT_INT(m, SOUND_MIXER_NRDEVICES);
_EXPORT_INT(m, SOUND_MIXER_VOLUME);
_EXPORT_INT(m, SOUND_MIXER_BASS);
_EXPORT_INT(m, SOUND_MIXER_TREBLE);