Changeset 6a50b9e


Ignore:
Timestamp:
Mar 3, 2013, 10:20:30 PM (12 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:
6514bb6
Parents:
68d0492
Message:

python/aubiomodule.c: add midi/bin/freq conversion

Location:
python
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • python/aubiomodule.c

    r68d0492 r6a50b9e  
    3838
    3939  return result;
     40}
     41
     42static char Py_bintomidi_doc[] = "convert bin to midi";
     43
     44static PyObject *
     45Py_bintomidi (PyObject * self, PyObject * args)
     46{
     47  smpl_t input, samplerate, fftsize;
     48  smpl_t output;
     49
     50  if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
     51    return NULL;
     52  }
     53
     54  output = aubio_bintomidi (input, samplerate, fftsize);
     55
     56  return (PyObject *)PyFloat_FromDouble (output);
     57}
     58
     59static char Py_miditobin_doc[] = "convert midi to bin";
     60
     61static PyObject *
     62Py_miditobin (PyObject * self, PyObject * args)
     63{
     64  smpl_t input, samplerate, fftsize;
     65  smpl_t output;
     66
     67  if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
     68    return NULL;
     69  }
     70
     71  output = aubio_miditobin (input, samplerate, fftsize);
     72
     73  return (PyObject *)PyFloat_FromDouble (output);
     74}
     75
     76static char Py_bintofreq_doc[] = "convert bin to freq";
     77
     78static PyObject *
     79Py_bintofreq (PyObject * self, PyObject * args)
     80{
     81  smpl_t input, samplerate, fftsize;
     82  smpl_t output;
     83
     84  if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
     85    return NULL;
     86  }
     87
     88  output = aubio_bintofreq (input, samplerate, fftsize);
     89
     90  return (PyObject *)PyFloat_FromDouble (output);
     91}
     92
     93static char Py_freqtobin_doc[] = "convert freq to bin";
     94
     95static PyObject *
     96Py_freqtobin (PyObject * self, PyObject * args)
     97{
     98  smpl_t input, samplerate, fftsize;
     99  smpl_t output;
     100
     101  if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
     102    return NULL;
     103  }
     104
     105  output = aubio_freqtobin (input, samplerate, fftsize);
     106
     107  return (PyObject *)PyFloat_FromDouble (output);
     108}
     109
     110static char Py_freqtomidi_doc[] = "convert freq to midi";
     111
     112static PyObject *
     113Py_freqtomidi (PyObject * self, PyObject * args)
     114{
     115  smpl_t input;
     116  smpl_t output;
     117
     118  if (!PyArg_ParseTuple (args, "|f", &input)) {
     119    return NULL;
     120  }
     121
     122  output = aubio_freqtomidi (input);
     123
     124  return (PyObject *)PyFloat_FromDouble (output);
     125}
     126
     127static char Py_miditofreq_doc[] = "convert midi to freq";
     128
     129static PyObject *
     130Py_miditofreq (PyObject * self, PyObject * args)
     131{
     132  smpl_t input;
     133  smpl_t output;
     134
     135  if (!PyArg_ParseTuple (args, "|f", &input)) {
     136    return NULL;
     137  }
     138
     139  output = aubio_miditofreq (input);
     140
     141  return (PyObject *)PyFloat_FromDouble (output);
    40142}
    41143
     
    107209
    108210static PyMethodDef aubio_methods[] = {
     211  {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc},
     212  {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc},
     213  {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc},
     214  {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc},
     215  {"miditofreq", Py_miditofreq, METH_VARARGS, Py_miditofreq_doc},
     216  {"freqtomidi", Py_freqtomidi, METH_VARARGS, Py_freqtomidi_doc},
    109217  {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc},
    110   {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS,
    111     Py_zero_crossing_rate_doc},
     218  {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc},
    112219  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
    113220  {NULL, NULL} /* Sentinel */
Note: See TracChangeset for help on using the changeset viewer.