shithub: aubio

Download patch

ref: b5322759db58e013cc158bc987ff9f118ab3e501
parent: 6f3dfc0d00064611edc72bf18e648b7a130751ec
author: Paul Brossier <piem@piem.org>
date: Sat Sep 15 10:57:36 EDT 2018

python/ext/py-musicutils.*: add shift(fvec) and ishift(fvec)

--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -242,6 +242,8 @@
   {"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 */
 };
 
--- a/python/ext/py-musicutils.c
+++ b/python/ext/py-musicutils.c
@@ -133,3 +133,51 @@
 
   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);
+}
--- a/python/ext/py-musicutils.h
+++ b/python/ext/py-musicutils.h
@@ -71,4 +71,34 @@
 
 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 */