Changeset 96fe713 for interfaces


Ignore:
Timestamp:
Dec 5, 2009, 1:44:11 AM (15 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:
0f045b2
Parents:
7a7b00f
Message:

interfaces/python: towards mono

Location:
interfaces/python
Files:
1 added
7 edited

Legend:

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

    r7a7b00f r96fe713  
    66#include <aubio.h>
    77
    8 #define Py_default_vector_length   1024
    9 #define Py_default_vector_channels 1
     8#define Py_default_vector_length 1024
     9#define Py_default_vector_height 1
    1010
    1111#define Py_aubio_default_samplerate 44100
     
    2525
    2626*/
    27 #define AUBIO_DO_CASTING 0
    2827
    2928typedef struct
     
    3231  fvec_t * o;
    3332  uint_t length;
    34   uint_t channels;
    3533} Py_fvec;
    3634extern PyTypeObject Py_fvecType;
     
    3836extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
    3937extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self);
     38
     39typedef struct
     40{
     41  PyObject_HEAD
     42  fmat_t * o;
     43  uint_t length;
     44  uint_t height;
     45} Py_fmat;
     46extern PyTypeObject Py_fmatType;
     47extern PyObject *PyAubio_FmatToArray (Py_fmat * self);
     48extern PyObject *PyAubio_CFmatToArray (fmat_t * self);
     49extern Py_fmat *PyAubio_ArrayToFmat (PyObject * self);
    4050
    4151typedef struct
  • interfaces/python/aubiomodule.c

    r7a7b00f r96fe713  
    122122
    123123  if ((PyType_Ready (&Py_fvecType) < 0)
     124      || (PyType_Ready (&Py_fmatType) < 0)
    124125      || (PyType_Ready (&Py_cvecType) < 0)
    125126      || (PyType_Ready (&Py_filterType) < 0)
     
    148149  Py_INCREF (&Py_fvecType);
    149150  PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType);
     151  Py_INCREF (&Py_fmatType);
     152  PyModule_AddObject (m, "fmat", (PyObject *) & Py_fmatType);
    150153  Py_INCREF (&Py_cvecType);
    151154  PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType);
  • interfaces/python/aubiowraphell.h

    r7a7b00f r96fe713  
    9494
    9595// some more helpers
    96 #define AUBIO_NEW_VEC(name, type, lengthval, channelsval) \
     96#define AUBIO_NEW_VEC(name, type, lengthval) \
    9797  name = (type *) PyObject_New (type, & type ## Type); \
    98   name->channels = channelsval; \
    9998  name->length = lengthval;
  • interfaces/python/gen_pyobject.py

    r7a7b00f r96fe713  
    6969# move into the C library at some point.
    7070defaultsizes = {
    71     'resampler':    ('input->length * self->ratio', 'input->channels'),
    72     'specdesc':     ('1', 'fftgrain->channels'),
    73     'onset':        ('1', 'self->channels'),
    74     'pitchyin':     ('1', 'in->channels'),
    75     'pitchyinfft':  ('1', 'in->channels'),
    76     'pitchschmitt': ('1', 'in->channels'),
    77     'pitchmcomb':   ('1', 'self->channels'),
    78     'pitchfcomb':   ('1', 'self->channels'),
    79     'pitch':        ('1', 'self->channels'),
    80     'tss':          ('self->hop_size', 'self->channels'),
    81     'mfcc':         ('self->n_coeffs', 'in->channels'),
    82     'beattracking': ('self->hop_size', 'self->channels'),
    83     'tempo':        ('1', 'self->channels'),
    84     'peakpicker':   ('1', 'self->channels'),
     71    'resampler':    'input->length * self->ratio',
     72    'specdesc':     '1',
     73    'onset':        '1',
     74    'pitchyin':     '1',
     75    'pitchyinfft':  '1',
     76    'pitchschmitt': '1',
     77    'pitchmcomb':   '1',
     78    'pitchfcomb':   '1',
     79    'pitch':        '1',
     80    'tss':          'self->hop_size',
     81    'mfcc':         'self->n_coeffs',
     82    'beattracking': 'self->hop_size',
     83    'tempo':        '1',
     84    'peakpicker':   '1',
    8585}
    8686
     
    9999    'hop_size': 'Py_default_vector_length / 2',
    100100    # these should be alright
    101     'channels': 'Py_default_vector_channels',
    102101    'samplerate': 'Py_aubio_default_samplerate',
    103102    # now for the non obvious ones
     
    151150    newparams = get_params_types_names(newfunc)
    152151    # self->param1, self->param2, self->param3
    153     selfparams = ', self->'.join([p[1] for p in newparams])
     152    if len(newparams):
     153        selfparams = ', self->'+', self->'.join([p[1] for p in newparams])
     154    else:
     155        selfparams = ''
    154156    # "param1", "param2", "param3"
    155157    paramnames = ", ".join(["\""+p[1]+"\"" for p in newparams])
     
    179181Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
    180182{
     183  Py_%(name)s *self;
    181184""" % locals()
    182185    for ptype, pname in newparams:
     
    186189""" % locals()
    187190    # now the actual PyArg_Parse
    188     s += """\
    189   Py_%(name)s *self;
     191    if len(paramnames):
     192        s += """\
    190193  static char *kwlist[] = { %(paramnames)s, NULL };
    191194
     
    194197    return NULL;
    195198  }
     199""" % locals()
     200    s += """\
    196201
    197202  self = (Py_%(name)s *) pytype->tp_alloc (pytype, 0);
     
    238243}
    239244
    240 AUBIO_INIT(%(name)s, self->%(selfparams)s)
     245AUBIO_INIT(%(name)s %(selfparams)s)
    241246
    242247AUBIO_DEL(%(name)s)
     
    287292        outputvecs = "\n  ".join([aubio2pyaubio[p[0]]+" * " + p[-1] + ";" for p in outputparams])
    288293        outputcreate = "\n  ".join(["""\
    289 AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s, %(channels)s)
    290   %(name)s->o = new_%(autype)s (%(length)s, %(channels)s);""" % \
     294AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s)
     295  %(name)s->o = new_%(autype)s (%(length)s);""" % \
    291296    {'name': p[-1], 'pytype': aubio2pyaubio[p[0]], 'autype': p[0][:-3],
    292         'length': defaultsizes[name][0], 'channels': defaultsizes[name][1]} \
     297        'length': defaultsizes[name]} \
    293298        for p in outputparams])
    294299        if len(outputparams) > 1:
  • interfaces/python/py-fft.c

    r7a7b00f r96fe713  
    33static char Py_fft_doc[] = "fft object";
    44
    5 AUBIO_DECLARE(fft, uint_t win_s; uint_t channels)
     5AUBIO_DECLARE(fft, uint_t win_s)
    66
    77//AUBIO_NEW(fft)
     
    99Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1010{
    11   int win_s = 0, channels = 0;
     11  int win_s = 0;
    1212  Py_fft *self;
    13   static char *kwlist[] = { "win_s", "channels", NULL };
     13  static char *kwlist[] = { "win_s", NULL };
    1414
    15   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
    16           &win_s, &channels)) {
     15  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist,
     16          &win_s)) {
    1717    return NULL;
    1818  }
     
    2525
    2626  self->win_s = Py_default_vector_length;
    27   self->channels = Py_default_vector_channels;
    2827
    2928  if (self == NULL) {
     
    3938  }
    4039
    41   if (channels > 0) {
    42     self->channels = channels;
    43   } else if (channels < 0) {
    44     PyErr_SetString (PyExc_ValueError,
    45         "can not use negative number of filters");
    46     return NULL;
    47   }
    48 
    4940  return (PyObject *) self;
    5041}
    5142
    5243
    53 AUBIO_INIT(fft, self->win_s, self->channels)
     44AUBIO_INIT(fft, self->win_s)
    5445
    5546AUBIO_DEL(fft)
     
    7364
    7465  output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
    75   output->channels = vec->channels;
    7666  output->length = ((Py_fft *) self)->win_s;
    77   output->o = new_cvec(((Py_fft *) self)->win_s, vec->channels);
     67  output->o = new_cvec(((Py_fft *) self)->win_s);
    7868
    7969  // compute the function
     
    8777  {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
    8878    "size of the window"},
    89   {"channels", T_INT, offsetof (Py_fft, channels), READONLY,
    90     "number of channels"},
    9179AUBIO_MEMBERS_STOP(fft)
    9280
     
    10997
    11098  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
    111   output->channels = vec->channels;
    11299  output->length = ((Py_fft *) self)->win_s;
    113   output->o = new_fvec(output->length, output->channels);
     100  output->o = new_fvec(output->length);
    114101
    115102  // compute the function
  • interfaces/python/py-filter.c

    r7a7b00f r96fe713  
    66  aubio_filter_t * o;
    77  uint_t order;
    8   uint_t channels;
    98} Py_filter;
    109
     
    1413Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
    1514{
    16   int order= 0, channels = 0;
     15  int order= 0;
    1716  Py_filter *self;
    18   static char *kwlist[] = { "order", "channels", NULL };
     17  static char *kwlist[] = { "order", NULL };
    1918
    2019  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
    21           &order, &channels)) {
     20          &order)) {
    2221    return NULL;
    2322  }
     
    3029
    3130  self->order = 7;
    32   self->channels = Py_default_vector_channels;
    3331
    3432  if (order > 0) {
     
    4038  }
    4139
    42   if (channels > 0) {
    43     self->channels = channels;
    44   } else if (channels < 0) {
    45     PyErr_SetString (PyExc_ValueError,
    46         "can not use negative number of channels");
    47     return NULL;
    48   }
    49 
    5040  return (PyObject *) self;
    5141}
     
    5444Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds)
    5545{
    56   self->o = new_aubio_filter (self->order, self->channels);
     46  self->o = new_aubio_filter (self->order);
    5747  if (self->o == NULL) {
    5848    return -1;
     
    9282#if 1
    9383  aubio_filter_do (((Py_filter *)self)->o, vec->o);
    94   Py_INCREF(vec);
     84  PyArray_INCREF((PyArrayObject*)vec);
    9585  return (PyObject *)vec;
    9686#else
    9787  Py_fvec *copy = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
    98   copy->o = new_fvec(vec->o->length, vec->o->channels);
     88  copy->o = new_fvec(vec->o->length);
    9989  aubio_filter_do_outplace (((Py_filter *)self)->o, vec->o, copy->o);
    10090  return (PyObject *)copy;
     
    142132  {"order", T_INT, offsetof (Py_filter, order), READONLY,
    143133      "order of the filter"},
    144   {"channels", T_INT, offsetof (Py_filter, channels), READONLY,
    145       "number of channels"},
    146134  {NULL}                        /* Sentinel */
    147135};
  • interfaces/python/py-filterbank.c

    r7a7b00f r96fe713  
    6868
    6969  output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
    70   output->channels = vec->channels;
    7170  output->length = self->n_filters;
    72   output->o = new_fvec(self->n_filters, vec->channels);
     71  output->o = new_fvec(self->n_filters);
    7372
    7473  // compute the function
     
    138137Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused)
    139138{
    140   Py_fvec *output = (Py_fvec *) PyObject_New (Py_fvec, &Py_fvecType);
    141   output->channels = self->n_filters;
    142   output->length = self->win_s / 2 + 1;
     139  Py_fmat *output = (Py_fmat *) PyObject_New (Py_fmat, &Py_fvecType);
    143140  output->o = aubio_filterbank_get_coeffs (self->o);
    144   return (PyObject *)PyAubio_FvecToArray(output);
     141  return (PyObject *)PyAubio_FmatToArray(output);
    145142}
    146143
Note: See TracChangeset for help on using the changeset viewer.