diff --git a/alsaaudio.c b/alsaaudio.c index fb1c8de..7ca6a91 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -1423,8 +1423,6 @@ alsapcm_read(alsapcm_t *self, PyObject *args) static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args) { - snd_pcm_state_t state; - int res; int datalen; char *data; PyObject *rc = NULL; @@ -1464,10 +1462,11 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args) return NULL; } + int res; snd_pcm_state_t state = snd_pcm_state(self->handle); - if (state != SND_PCM_STATE_SETUP) { - res = snd_pcm_prepare(self->handle)); + if ((state != SND_PCM_STATE_XRUN && state != SND_PCM_STATE_SETUP) || + (res = snd_pcm_prepare(self->handle)) >= 0) { Py_BEGIN_ALLOW_THREADS res = snd_pcm_writei(self->handle, data, datalen/self->framesize); if (res == -EPIPE) {