diff --git a/alsaaudio.c b/alsaaudio.c index 8508730..a9bfc58 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -840,6 +840,21 @@ alsa_asoundlib_version(PyObject * module, PyObject *args) return PyUnicode_FromString(snd_asoundlib_version()); } +static PyObject * +alsapcm_state(alsapcm_t *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args,":state")) + return NULL; + + if (!self->handle) + { + PyErr_SetString(ALSAAudioError, "PCM device is closed"); + return NULL; + } + + return PyLong_FromUnsignedLong((unsigned long) snd_pcm_state(self->handle)); +} + static PyObject * alsapcm_htimestamp(alsapcm_t *self, PyObject *args) { @@ -1605,6 +1620,7 @@ static PyMethodDef alsapcm_methods[] = { {"get_tstamp_mode", (PyCFunction) alsapcm_get_tstamp_mode, METH_VARARGS}, {"dumpinfo", (PyCFunction)alsapcm_dumpinfo, METH_VARARGS}, {"info", (PyCFunction)alsapcm_info, METH_VARARGS}, + {"state", (PyCFunction)alsapcm_state, METH_VARARGS}, {"getformats", (PyCFunction)alsapcm_getformats, METH_VARARGS}, {"getratebounds", (PyCFunction)alsapcm_getratemaxmin, METH_VARARGS}, {"getrates", (PyCFunction)alsapcm_getrates, METH_VARARGS}, @@ -3054,6 +3070,16 @@ PyObject *PyInit_alsaaudio(void) _EXPORT_INT(m, "PCM_FORMAT_DSD_U32_BE", SND_PCM_FORMAT_DSD_U32_BE); #endif + _EXPORT_INT(m, "PCM_STATE_OPEN", SND_PCM_STATE_OPEN); + _EXPORT_INT(m, "PCM_STATE_SETUP", SND_PCM_STATE_SETUP); + _EXPORT_INT(m, "PCM_STATE_PREPARED", SND_PCM_STATE_PREPARED); + _EXPORT_INT(m, "PCM_STATE_RUNNING", SND_PCM_STATE_RUNNING); + _EXPORT_INT(m, "PCM_STATE_XRUN", SND_PCM_STATE_XRUN); + _EXPORT_INT(m, "PCM_STATE_DRAINING", SND_PCM_STATE_DRAINING); + _EXPORT_INT(m, "PCM_STATE_PAUSED", SND_PCM_STATE_PAUSED); + _EXPORT_INT(m, "PCM_STATE_SUSPENDED", SND_PCM_STATE_SUSPENDED); + _EXPORT_INT(m, "PCM_STATE_DISCONNECTED", SND_PCM_STATE_DISCONNECTED); + /* Mixer stuff */ _EXPORT_INT(m, "MIXER_CHANNEL_ALL", MIXER_CHANNEL_ALL); diff --git a/doc/libalsaaudio.rst b/doc/libalsaaudio.rst index 2ed5f7a..9b8f479 100644 --- a/doc/libalsaaudio.rst +++ b/doc/libalsaaudio.rst @@ -297,6 +297,21 @@ PCM objects have the following methods: Dumps the PCM object's configured parameters to stdout. +.. method:: PCM.state() + + Returs the current state of the stream, which can be one of + :const:`PCM_STATE_OPEN` (this should not actually happen), + :const:`PCM_STATE_SETUP` (after :func:`drop` or :func:`drain`), + :const:`PCM_STATE_PREPARED` (after construction), + :const:`PCM_STATE_RUNNING`, + :const:`PCM_STATE_XRUN`, + :const:`PCM_STATE_DRAINING`, + :const:`PCM_STATE_PAUSED`, + :const:`PCM_STATE_SUSPENDED`, and + :const:`PCM_STATE_DISCONNECTED`. + + *New in 0.10* + .. method:: PCM.read() In :const:`PCM_NORMAL` mode, this function blocks until a full period is