Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (8 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:
4b9443c4
Parents:
60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into notes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-phasevoc.c

    r60fc05b rf264b17  
    1 #include "aubiowraphell.h"
     1#include "aubio-types.h"
    22
    33static char Py_pvoc_doc[] = "pvoc object";
    44
    5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s)
    6 
    7 //AUBIO_NEW(pvoc)
     5typedef struct
     6{
     7  PyObject_HEAD
     8  aubio_pvoc_t * o;
     9  uint_t win_s;
     10  uint_t hop_s;
     11  fvec_t vecin;
     12  cvec_t cvecin;
     13  PyObject *output;
     14  cvec_t c_output;
     15  PyObject *routput;
     16  fvec_t c_routput;
     17} Py_pvoc;
     18
     19
    820static PyObject *
    921Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
     
    5062}
    5163
    52 
    53 AUBIO_INIT(pvoc, self->win_s, self->hop_s)
    54 
    55 AUBIO_DEL(pvoc)
    56 
    57 static PyObject *
     64static int
     65Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
     66{
     67  self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
     68  if (self->o == NULL) {
     69    PyErr_Format(PyExc_RuntimeError,
     70        "failed creating pvoc with win_s=%d, hop_s=%d",
     71        self->win_s, self->hop_s);
     72    return -1;
     73  }
     74
     75  self->output = new_py_cvec(self->win_s);
     76  self->routput = new_py_fvec(self->hop_s);
     77
     78  return 0;
     79}
     80
     81
     82static void
     83Py_pvoc_del (Py_pvoc *self, PyObject *unused)
     84{
     85  Py_XDECREF(self->output);
     86  Py_XDECREF(self->routput);
     87  if (self->o) {
     88    del_aubio_pvoc(self->o);
     89  }
     90  Py_TYPE(self)->tp_free((PyObject *) self);
     91}
     92
     93
     94static PyObject *
    5895Py_pvoc_do(Py_pvoc * self, PyObject * args)
    5996{
    6097  PyObject *input;
    61   fvec_t *vec;
    62   cvec_t *output;
    6398
    6499  if (!PyArg_ParseTuple (args, "O", &input)) {
     
    66101  }
    67102
    68   vec = PyAubio_ArrayToCFvec (input);
    69 
    70   if (vec == NULL) {
    71     return NULL;
    72   }
    73 
    74   output = new_cvec(self->win_s);
    75 
     103  if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
     104    return NULL;
     105  }
     106
     107  if (self->vecin.length != self->hop_s) {
     108    PyErr_Format(PyExc_ValueError,
     109                 "input fvec has length %d, but pvoc expects length %d",
     110                 self->vecin.length, self->hop_s);
     111    return NULL;
     112  }
     113
     114  Py_INCREF(self->output);
     115  if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
     116    return NULL;
     117  }
    76118  // compute the function
    77   aubio_pvoc_do (self->o, vec, output);
    78   return (PyObject *)PyAubio_CCvecToPyCvec(output);
    79 }
    80 
    81 AUBIO_MEMBERS_START(pvoc)
     119  aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output));
     120  return self->output;
     121}
     122
     123static PyMemberDef Py_pvoc_members[] = {
    82124  {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
    83125    "size of the window"},
    84126  {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
    85127    "size of the hop"},
    86 AUBIO_MEMBERS_STOP(pvoc)
    87 
    88 static PyObject *
     128  { NULL } // sentinel
     129};
     130
     131static PyObject *
    89132Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
    90133{
    91134  PyObject *input;
    92   cvec_t *vec;
    93   fvec_t *output;
    94 
    95135  if (!PyArg_ParseTuple (args, "O", &input)) {
    96136    return NULL;
    97137  }
    98138
    99   vec = PyAubio_ArrayToCCvec (input);
    100 
    101   if (vec == NULL) {
    102     return NULL;
    103   }
    104 
    105   output = new_fvec(self->hop_s);
    106 
     139  if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) {
     140    return NULL;
     141  }
     142
     143  if (self->cvecin.length != self->win_s / 2 + 1) {
     144    PyErr_Format(PyExc_ValueError,
     145                 "input cvec has length %d, but pvoc expects length %d",
     146                 self->cvecin.length, self->win_s / 2 + 1);
     147    return NULL;
     148  }
     149
     150  Py_INCREF(self->routput);
     151  if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
     152    return NULL;
     153  }
    107154  // compute the function
    108   aubio_pvoc_rdo (self->o, vec, output);
    109   return (PyObject *)PyAubio_CFvecToArray(output);
     155  aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput));
     156  return self->routput;
    110157}
    111158
     
    116163};
    117164
    118 AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")
     165PyTypeObject Py_pvocType = {
     166  PyVarObject_HEAD_INIT (NULL, 0)
     167  "aubio.pvoc",
     168  sizeof (Py_pvoc),
     169  0,
     170  (destructor) Py_pvoc_del,
     171  0,
     172  0,
     173  0,
     174  0,
     175  0,
     176  0,
     177  0,
     178  0,
     179  0,
     180  (ternaryfunc)Py_pvoc_do,
     181  0,
     182  0,
     183  0,
     184  0,
     185  Py_TPFLAGS_DEFAULT,
     186  Py_pvoc_doc,
     187  0,
     188  0,
     189  0,
     190  0,
     191  0,
     192  0,
     193  Py_pvoc_methods,
     194  Py_pvoc_members,
     195  0,
     196  0,
     197  0,
     198  0,
     199  0,
     200  0,
     201  (initproc) Py_pvoc_init,
     202  0,
     203  Py_pvoc_new,
     204  0,
     205  0,
     206  0,
     207  0,
     208  0,
     209  0,
     210  0,
     211  0,
     212  0,
     213};
Note: See TracChangeset for help on using the changeset viewer.