From b5322759db58e013cc158bc987ff9f118ab3e501 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 15 Sep 2018 14:57:36 +0200 Subject: [PATCH] python/ext/py-musicutils.*: add shift(fvec) and ishift(fvec) --- python/ext/aubiomodule.c | 2 ++ python/ext/py-musicutils.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ python/ext/py-musicutils.h | 30 +++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index 76ed9c9b..e97c3d35 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -242,6 +242,8 @@ static PyMethodDef aubio_methods[] = { {"silence_detection", Py_aubio_silence_detection, METH_VARARGS, Py_aubio_silence_detection_doc}, {"level_detection", Py_aubio_level_detection, METH_VARARGS, Py_aubio_level_detection_doc}, {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc}, + {"shift", Py_aubio_shift, METH_VARARGS, Py_aubio_shift_doc}, + {"ishift", Py_aubio_ishift, METH_VARARGS, Py_aubio_ishift_doc}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/python/ext/py-musicutils.c b/python/ext/py-musicutils.c index 3078e079..a0d450a4 100644 --- a/python/ext/py-musicutils.c +++ b/python/ext/py-musicutils.c @@ -133,3 +133,51 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) return level_detection; } + +PyObject * +Py_aubio_shift(PyObject *self, PyObject *args) +{ + PyObject *input; + fvec_t vec; + + if (!PyArg_ParseTuple (args, "O:shift", &input)) { + return NULL; + } + + if (input == NULL) { + return NULL; + } + + if (!PyAubio_ArrayToCFvec(input, &vec)) { + return NULL; + } + + fvec_shift(&vec); + + //Py_RETURN_NONE; + return (PyObject *) PyAubio_CFvecToArray(&vec); +} + +PyObject * +Py_aubio_ishift(PyObject *self, PyObject *args) +{ + PyObject *input; + fvec_t vec; + + if (!PyArg_ParseTuple (args, "O:shift", &input)) { + return NULL; + } + + if (input == NULL) { + return NULL; + } + + if (!PyAubio_ArrayToCFvec(input, &vec)) { + return NULL; + } + + fvec_ishift(&vec); + + //Py_RETURN_NONE; + return (PyObject *) PyAubio_CFvecToArray(&vec); +} diff --git a/python/ext/py-musicutils.h b/python/ext/py-musicutils.h index 54ee2305..cbe94aeb 100644 --- a/python/ext/py-musicutils.h +++ b/python/ext/py-musicutils.h @@ -71,4 +71,34 @@ static char Py_aubio_level_detection_doc[] = "" PyObject * Py_aubio_level_detection(PyObject *self, PyObject *args); +static char Py_aubio_shift_doc[] = "" +"Swap left and right partitions of a vector\n" +"\n" +"Returns the swapped vector. The input vector is also modified.\n" +"\n" +"For a vector of length N, the partition is split at index N - N//2.\n" +"\n" +"Example\n" +"-------\n" +"\n" +">>> import numpy\n" +">>> shift(numpy.arange(3, dtype=aubio.float_type))\n" +"array([2., 0., 1.], dtype=" AUBIO_NPY_SMPL_STR ")"; +PyObject * Py_aubio_shift(PyObject *self, PyObject *args); + +static char Py_aubio_ishift_doc[] = "" +"Swap right and left partitions of a vector\n" +"\n" +"Returns the swapped vector. The input vector is also modified.\n" +"\n" +"Unlike with shift(), the partition is split at index N//2.\n" +"\n" +"Example\n" +"-------\n" +"\n" +">>> import numpy\n" +">>> ishift(numpy.arange(3, dtype=aubio.float_type))\n" +"array([1., 2., 0.], dtype=" AUBIO_NPY_SMPL_STR ")"; +PyObject * Py_aubio_ishift(PyObject *self, PyObject *args); + #endif /* PY_AUBIO_MUSICUTILS_H */ -- 2.11.0