From bc66f1db2770b80574350d4d38ba3702b5b42288 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 17 Nov 2018 02:31:36 +0100 Subject: [PATCH] [py] add meltohz and hztomel with minimal doc --- python/ext/aubiomodule.c | 4 +++ python/ext/py-musicutils.c | 54 ++++++++++++++++++++++++++++++++++++ python/ext/py-musicutils.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) diff --git a/python/ext/aubiomodule.c b/python/ext/aubiomodule.c index 0fa8ac74..03450647 100644 --- a/python/ext/aubiomodule.c +++ b/python/ext/aubiomodule.c @@ -372,6 +372,10 @@ static PyMethodDef aubio_methods[] = { {"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}, + {"hztomel", Py_aubio_hztomel, METH_VARARGS|METH_KEYWORDS, Py_aubio_hztomel_doc}, + {"meltohz", Py_aubio_meltohz, METH_VARARGS|METH_KEYWORDS, Py_aubio_meltohz_doc}, + {"hztomel_htk", Py_aubio_hztomel_htk, METH_VARARGS, Py_aubio_hztomel_htk_doc}, + {"meltohz_htk", Py_aubio_meltohz_htk, METH_VARARGS, Py_aubio_meltohz_htk_doc}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/python/ext/py-musicutils.c b/python/ext/py-musicutils.c index a0d450a4..32239456 100644 --- a/python/ext/py-musicutils.c +++ b/python/ext/py-musicutils.c @@ -181,3 +181,57 @@ Py_aubio_ishift(PyObject *self, PyObject *args) //Py_RETURN_NONE; return (PyObject *) PyAubio_CFvecToArray(&vec); } + +PyObject* +Py_aubio_hztomel(PyObject *self, PyObject *args, PyObject *kwds) +{ + smpl_t v; + PyObject *htk = NULL; + static char *kwlist[] = {"f", "htk", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O", + kwlist, &v, &htk)) + { + return NULL; + } + if (htk != NULL && PyObject_IsTrue(htk) == 1) + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v)); + else + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v)); +} + +PyObject* +Py_aubio_meltohz(PyObject *self, PyObject *args, PyObject *kwds) +{ + smpl_t v; + PyObject *htk = NULL; + static char *kwlist[] = {"m", "htk", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, kwds, AUBIO_NPY_SMPL_CHR "|O", + kwlist, &v, &htk)) + { + return NULL; + } + if (htk != NULL && PyObject_IsTrue(htk) == 1) + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v)); + else + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v)); +} + +PyObject* +Py_aubio_hztomel_htk(PyObject *self, PyObject *args) +{ + smpl_t v; + if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) { + return NULL; + } + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v)); +} + +PyObject* +Py_aubio_meltohz_htk(PyObject *self, PyObject *args) +{ + smpl_t v; + if (!PyArg_ParseTuple(args, AUBIO_NPY_SMPL_CHR, &v)) { + return NULL; + } + return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v)); +} diff --git a/python/ext/py-musicutils.h b/python/ext/py-musicutils.h index 02415e42..27698d13 100644 --- a/python/ext/py-musicutils.h +++ b/python/ext/py-musicutils.h @@ -300,4 +300,72 @@ static char Py_aubio_ishift_doc[] = "" ""; PyObject * Py_aubio_ishift(PyObject *self, PyObject *args); +static char Py_aubio_hztomel_doc[] = "" +"hztomel(f, htk=False)\n" +"\n" +"Convert a scalar from frequency to mel scale.\n" +"\n" +"Parameters\n" +"----------\n" +"m : float\n" +" input frequency, in Hz\n" +"htk : bool\n" +" if `True`, use Htk mel scale instead of Slaney.\n" +"\n" +"Returns\n" +"-------\n" +"float\n" +" output mel\n" +"\n" +"See Also\n" +"--------\n" +"meltohz\n" +""; +PyObject * Py_aubio_hztomel(PyObject *self, PyObject *args); + +static char Py_aubio_meltohz_doc[] = "" +"meltohz(m, htk=False)\n" +"\n" +"Convert a scalar from mel scale to frequency.\n" +"\n" +"Parameters\n" +"----------\n" +"m : float\n" +" input mel\n" +"htk : bool\n" +" if `True`, use Htk mel scale instead of Slaney.\n" +"\n" +"Returns\n" +"-------\n" +"float\n" +" output frequency, in Hz\n" +"\n" +"See Also\n" +"--------\n" +"hztomel\n" +""; +PyObject * Py_aubio_meltohz(PyObject *self, PyObject *args); + +static char Py_aubio_hztomel_htk_doc[] = "" +"hztomel_htk(m)\n" +"\n" +"Same as `hztomel(m, htk=True)`\n" +"\n" +"See Also\n" +"--------\n" +"hztomel\n" +""; +PyObject * Py_aubio_hztomel_htk(PyObject *self, PyObject *args); + +static char Py_aubio_meltohz_htk_doc[] = "" +"meltohz_htk(m)\n" +"\n" +"Same as `meltohz(m, htk=True)`\n" +"\n" +"See Also\n" +"--------\n" +"meltohz\n" +""; +PyObject * Py_aubio_meltohz_htk(PyObject *self, PyObject *args); + #endif /* PY_AUBIO_MUSICUTILS_H */ -- 2.11.0