Changeset ede5d38 for python/ext


Ignore:
Timestamp:
Apr 29, 2016, 9:19:28 PM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
1ee5e21
Parents:
ee092a8
Message:

python/ext/aubio-types.h: add new_py_ functions to create PyObjects? instead of fvec_t, apply to py-fft.c

Location:
python/ext
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubio-types.h

    ree092a8 rede5d38  
    5353extern PyTypeObject Py_cvecType;
    5454
     55PyObject * new_py_fvec(uint_t length);
     56PyObject * new_py_cvec(uint_t length);
     57PyObject * new_py_fmat(uint_t height, uint_t length);
     58
    5559// defined in aubio-proxy.c
    5660extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
  • python/ext/aubioproxy.c

    ree092a8 rede5d38  
    11#include "aubio-types.h"
     2
     3PyObject *
     4new_py_fvec(uint_t length) {
     5    npy_intp dims[] = { length, 1 };
     6    return PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
     7}
     8
     9PyObject *
     10new_py_fmat(uint_t height, uint_t length) {
     11    npy_intp dims[] = { height, length, 1 };
     12    return PyArray_ZEROS(2, dims, AUBIO_NPY_SMPL, 0);
     13}
    214
    315PyObject *
  • python/ext/py-cvec.c

    ree092a8 rede5d38  
    2121
    2222static char Py_cvec_doc[] = "cvec object";
     23
     24
     25PyObject *
     26new_py_cvec(uint_t length) {
     27  Py_cvec* vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
     28  npy_intp dims[] = { length / 2 + 1, 1 };
     29  vec->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
     30  vec->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
     31  vec->length = length / 2 + 1;
     32  return (PyObject*)vec;
     33}
    2334
    2435PyObject *
     
    4051  if (PyObject_TypeCheck (input, &Py_cvecType)) {
    4152      Py_cvec * in = (Py_cvec *)input;
    42       if (in->norm == NULL) {
    43         npy_intp dims[] = { in->length, 1 };
    44         in->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
    45       }
    46       if (in->phas == NULL) {
    47         npy_intp dims[] = { in->length, 1 };
    48         in->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
    49       }
    5053      i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0);
    5154      i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0);
     
    9295Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds)
    9396{
    94   self->norm = NULL;
    95   self->phas = NULL;
     97  npy_intp dims[] = { self->length, 1 };
     98  self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
     99  self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
    96100  return 0;
    97101}
     
    100104Py_cvec_del (Py_cvec * self)
    101105{
    102   Py_XDECREF(self->norm);
    103   Py_XDECREF(self->phas);
     106  Py_DECREF(self->norm);
     107  Py_DECREF(self->phas);
    104108  Py_TYPE(self)->tp_free ((PyObject *) self);
    105109}
     
    135139Py_cvec_get_norm (Py_cvec * self, void *closure)
    136140{
    137   // if it norm hasn't been created, create it now
    138   if (self->norm == NULL) {
    139     npy_intp dims[] = { self->length, 1 };
    140     self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
    141   }
     141  // we want self->norm to still exist after our caller return it
    142142  Py_INCREF(self->norm);
    143143  return (PyObject*)(self->norm);
     
    147147Py_cvec_get_phas (Py_cvec * self, void *closure)
    148148{
    149   // if it phas hasn't been created, create it now
    150   if (self->phas == NULL) {
    151     npy_intp dims[] = { self->length, 1 };
    152     self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
    153   }
     149  // we want self->phas to still exist after our caller return it
    154150  Py_INCREF(self->phas);
    155151  return (PyObject *)(self->phas);
  • python/ext/py-fft.c

    ree092a8 rede5d38  
    1212  cvec_t cvecin;
    1313  // do / rdo output results
    14   cvec_t *out;
    15   fvec_t *rout;
     14  PyObject *doout;
     15  PyObject *rdoout;
    1616} Py_fft;
    1717
     
    5858  }
    5959
    60   self->out = new_cvec(self->win_s);
    61   self->rout = new_fvec(self->win_s);
     60  self->doout = new_py_cvec(self->win_s);
     61  self->rdoout = new_py_fvec(self->win_s);
    6262
    6363  return 0;
     
    6767Py_fft_del (Py_fft *self, PyObject *unused)
    6868{
     69  Py_XDECREF(self->doout);
     70  Py_XDECREF(self->rdoout);
    6971  del_aubio_fft(self->o);
    70   del_cvec(self->out);
    71   del_fvec(self->rout);
    7272  Py_TYPE(self)->tp_free((PyObject *) self);
    7373}
     
    8686  }
    8787
     88  cvec_t c_out;
     89  Py_INCREF(self->doout);
     90  if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
     91    return NULL;
     92  }
    8893  // compute the function
    89   aubio_fft_do (((Py_fft *)self)->o, &(self->vecin), self->out);
    90   // convert cvec to py_cvec
    91   return PyAubio_CCvecToPyCvec(self->out);
     94  aubio_fft_do (self->o, &(self->vecin), &c_out);
     95  return self->doout;
    9296}
    9397
     
    111115  }
    112116
     117  fvec_t out;
     118  Py_INCREF(self->rdoout);
     119  if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
     120    return NULL;
     121  }
    113122  // compute the function
    114   aubio_fft_rdo (self->o, &(self->cvecin), self->rout);
    115   return PyAubio_CFvecToArray(self->rout);
     123  aubio_fft_rdo (self->o, &(self->cvecin), &out);
     124  return self->rdoout;
    116125}
    117126
Note: See TracChangeset for help on using the changeset viewer.