#include "aubio-types.h"
PyObject *
+new_py_fvec(uint_t length) {
+ npy_intp dims[] = { length, 1 };
+ return PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
+}
+
+PyObject *
+new_py_fmat(uint_t height, uint_t length) {
+ npy_intp dims[] = { height, length, 1 };
+ return PyArray_ZEROS(2, dims, AUBIO_NPY_SMPL, 0);
+}
+
+PyObject *
PyAubio_CFvecToArray (fvec_t * self)
{
npy_intp dims[] = { self->length, 1 };
static char Py_cvec_doc[] = "cvec object";
+
+PyObject *
+new_py_cvec(uint_t length) {
+ Py_cvec* vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
+ npy_intp dims[] = { length / 2 + 1, 1 };
+ vec->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
+ vec->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
+ vec->length = length / 2 + 1;
+ return (PyObject*)vec;
+}
+
PyObject *
PyAubio_CCvecToPyCvec (cvec_t * input) {
if (input == NULL) {
PyAubio_PyCvecToCCvec (PyObject *input, cvec_t *i) {
if (PyObject_TypeCheck (input, &Py_cvecType)) {
Py_cvec * in = (Py_cvec *)input;
- if (in->norm == NULL) {
- npy_intp dims[] = { in->length, 1 };
- in->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
- }
- if (in->phas == NULL) {
- npy_intp dims[] = { in->length, 1 };
- in->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
- }
i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0);
i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0);
i->length = ((Py_cvec*)input)->length;
static int
Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds)
{
- self->norm = NULL;
- self->phas = NULL;
+ npy_intp dims[] = { self->length, 1 };
+ self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
+ self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
return 0;
}
static void
Py_cvec_del (Py_cvec * self)
{
- Py_XDECREF(self->norm);
- Py_XDECREF(self->phas);
+ Py_DECREF(self->norm);
+ Py_DECREF(self->phas);
Py_TYPE(self)->tp_free ((PyObject *) self);
}
PyObject *
Py_cvec_get_norm (Py_cvec * self, void *closure)
{
- // if it norm hasn't been created, create it now
- if (self->norm == NULL) {
- npy_intp dims[] = { self->length, 1 };
- self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
- }
+ // we want self->norm to still exist after our caller return it
Py_INCREF(self->norm);
return (PyObject*)(self->norm);
}
PyObject *
Py_cvec_get_phas (Py_cvec * self, void *closure)
{
- // if it phas hasn't been created, create it now
- if (self->phas == NULL) {
- npy_intp dims[] = { self->length, 1 };
- self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
- }
+ // we want self->phas to still exist after our caller return it
Py_INCREF(self->phas);
return (PyObject *)(self->phas);
}
fvec_t vecin;
cvec_t cvecin;
// do / rdo output results
- cvec_t *out;
- fvec_t *rout;
+ PyObject *doout;
+ PyObject *rdoout;
} Py_fft;
static PyObject *
return -1;
}
- self->out = new_cvec(self->win_s);
- self->rout = new_fvec(self->win_s);
+ self->doout = new_py_cvec(self->win_s);
+ self->rdoout = new_py_fvec(self->win_s);
return 0;
}
static void
Py_fft_del (Py_fft *self, PyObject *unused)
{
+ Py_XDECREF(self->doout);
+ Py_XDECREF(self->rdoout);
del_aubio_fft(self->o);
- del_cvec(self->out);
- del_fvec(self->rout);
Py_TYPE(self)->tp_free((PyObject *) self);
}
return NULL;
}
+ cvec_t c_out;
+ Py_INCREF(self->doout);
+ if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
+ return NULL;
+ }
// compute the function
- aubio_fft_do (((Py_fft *)self)->o, &(self->vecin), self->out);
- // convert cvec to py_cvec
- return PyAubio_CCvecToPyCvec(self->out);
+ aubio_fft_do (self->o, &(self->vecin), &c_out);
+ return self->doout;
}
static PyMemberDef Py_fft_members[] = {
return NULL;
}
+ fvec_t out;
+ Py_INCREF(self->rdoout);
+ if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
+ return NULL;
+ }
// compute the function
- aubio_fft_rdo (self->o, &(self->cvecin), self->rout);
- return PyAubio_CFvecToArray(self->rout);
+ aubio_fft_rdo (self->o, &(self->cvecin), &out);
+ return self->rdoout;
}
static PyMethodDef Py_fft_methods[] = {