From f6736ec43af445ca186590460266088edf1be512 Mon Sep 17 00:00:00 2001 From: Ronald van Elburg Date: Mon, 2 Nov 2020 18:43:16 +0100 Subject: [PATCH 1/3] first version timestamp function (cherry picked from commit 21d0527c7b91723b3bfc87ea889bd599dff12576) # Conflicts: # alsaaudio.c --- alsaaudio.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/alsaaudio.c b/alsaaudio.c index 2c587b7..851913e 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -639,6 +639,39 @@ alsapcm_dumpinfo(alsapcm_t *self, PyObject *args) return Py_None; } +static PyObject * +alsapcm_timestamp_raw(alsapcm_t *self, PyObject *args) +{ + snd_htimestamp_t tstamp; + snd_pcm_uframes_t avail; + PyObject *result = NULL; + // int err; + + /* snd_pcm_status_t *status; + snd_pcm_status_alloca(&status); + + if ((err = snd_pcm_status(self->handle, status)) < 0) { + printf("Stream status error: %s\n", snd_strerror(err)); + exit(0); + }*/ + + snd_pcm_htimestamp(self->handle , &avail, &tstamp); + + result = PyTuple_New(3); + PyTuple_SetItem(result, 0, PyLong_FromLongLong(tstamp.tv_sec)); + PyTuple_SetItem(result, 1, PyLong_FromLong(tstamp.tv_nsec)); + PyTuple_SetItem(result, 2, PyLong_FromLong(avail)); + + return result; +} + +PyDoc_STRVAR(pcm_timestampraw_doc, +"timestamp() -> tuple\n\ +\n\ +Returns a tuple containing the seconds since epoch in the first element \n\ +, nanoseconds in the second element, and available number of frames at the time of the time stamp.'. \n\ +"); + // auxiliary function @@ -1375,6 +1408,8 @@ static PyMethodDef alsapcm_methods[] = { {"setformat", (PyCFunction)alsapcm_setformat, METH_VARARGS, setformat_doc}, {"setperiodsize", (PyCFunction)alsapcm_setperiodsize, METH_VARARGS, setperiodsize_doc}, + {"timestamp_raw", (PyCFunction) alsapcm_timestamp_raw, METH_VARARGS, + pcm_timestampraw_doc}, {"dumpinfo", (PyCFunction)alsapcm_dumpinfo, METH_VARARGS}, {"getformats", (PyCFunction)alsapcm_getformats, METH_VARARGS, getformats_doc}, {"getratebounds", (PyCFunction)alsapcm_getratemaxmin, METH_VARARGS, getratebounds_doc}, From da71e01f9cc438a13e041f31f1c95a605748e6d4 Mon Sep 17 00:00:00 2001 From: Ronald van Elburg Date: Wed, 31 Mar 2021 16:27:55 +0200 Subject: [PATCH 2/3] Remove unused code from timestamp_raw function. --- alsaaudio.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/alsaaudio.c b/alsaaudio.c index 851913e..ef98785 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -639,21 +639,13 @@ alsapcm_dumpinfo(alsapcm_t *self, PyObject *args) return Py_None; } + static PyObject * alsapcm_timestamp_raw(alsapcm_t *self, PyObject *args) { snd_htimestamp_t tstamp; snd_pcm_uframes_t avail; PyObject *result = NULL; - // int err; - - /* snd_pcm_status_t *status; - snd_pcm_status_alloca(&status); - - if ((err = snd_pcm_status(self->handle, status)) < 0) { - printf("Stream status error: %s\n", snd_strerror(err)); - exit(0); - }*/ snd_pcm_htimestamp(self->handle , &avail, &tstamp); @@ -665,6 +657,7 @@ alsapcm_timestamp_raw(alsapcm_t *self, PyObject *args) return result; } + PyDoc_STRVAR(pcm_timestampraw_doc, "timestamp() -> tuple\n\ \n\ From 1a4c0541d786d3d5a03027f0d79a1cb6ee36f179 Mon Sep 17 00:00:00 2001 From: Ronald van Elburg Date: Fri, 2 Apr 2021 13:42:51 +0200 Subject: [PATCH 3/3] Change name timestamp_raw fuinction to htimestamp to follow the convention used in the rest of the library: that's the current convention (prefix the name with alsapcm_ for PCM methods). --- alsaaudio.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/alsaaudio.c b/alsaaudio.c index ef98785..ab961be 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -641,7 +641,7 @@ alsapcm_dumpinfo(alsapcm_t *self, PyObject *args) static PyObject * -alsapcm_timestamp_raw(alsapcm_t *self, PyObject *args) +alsapcm_htimestamp(alsapcm_t *self, PyObject *args) { snd_htimestamp_t tstamp; snd_pcm_uframes_t avail; @@ -658,12 +658,12 @@ alsapcm_timestamp_raw(alsapcm_t *self, PyObject *args) } -PyDoc_STRVAR(pcm_timestampraw_doc, -"timestamp() -> tuple\n\ +PyDoc_STRVAR(pcm_htimestamp_doc, +"htimestamp() -> tuple\n\ \n\ Returns a tuple containing the seconds since epoch in the first element \n\ -, nanoseconds in the second element, and available number of frames at the time of the time stamp.'. \n\ -"); +, nanoseconds in the second element, and number of frames available in \n\ + the buffer at the time of the time stamp. \n"); // auxiliary function @@ -1401,8 +1401,8 @@ static PyMethodDef alsapcm_methods[] = { {"setformat", (PyCFunction)alsapcm_setformat, METH_VARARGS, setformat_doc}, {"setperiodsize", (PyCFunction)alsapcm_setperiodsize, METH_VARARGS, setperiodsize_doc}, - {"timestamp_raw", (PyCFunction) alsapcm_timestamp_raw, METH_VARARGS, - pcm_timestampraw_doc}, + {"htimestamp", (PyCFunction) alsapcm_htimestamp, METH_VARARGS, + pcm_htimestamp_doc}, {"dumpinfo", (PyCFunction)alsapcm_dumpinfo, METH_VARARGS}, {"getformats", (PyCFunction)alsapcm_getformats, METH_VARARGS, getformats_doc}, {"getratebounds", (PyCFunction)alsapcm_getratemaxmin, METH_VARARGS, getratebounds_doc},