summaryrefslogtreecommitdiff
path: root/python/ext/py-musicutils.c
blob: 3078e07933b8494eef168705504124461ea3a683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "aubio-types.h"

PyObject *
Py_aubio_window(PyObject *self, PyObject *args)
{
  char_t *wintype = NULL;
  uint_t winlen = 0;
  fvec_t *window = NULL;

  if (!PyArg_ParseTuple (args, "|sI", &wintype, &winlen)) {
    return NULL;
  }

  window = new_aubio_window(wintype, winlen);
  if (window == NULL) {
    PyErr_SetString (PyExc_ValueError, "failed computing window");
    return NULL;
  }

  return (PyObject *) PyAubio_CFvecToArray(window);
}

PyObject *
Py_aubio_level_lin(PyObject *self, PyObject *args)
{
  PyObject *input;
  fvec_t vec;
  PyObject *level_lin;

  if (!PyArg_ParseTuple (args, "O:level_lin", &input)) {
    return NULL;
  }

  if (input == NULL) {
    return NULL;
  }

  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    return NULL;
  }

  level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
  if (level_lin == NULL) {
    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
    return NULL;
  }

  return level_lin;
}

PyObject *
Py_aubio_db_spl(PyObject *self, PyObject *args)
{
  PyObject *input;
  fvec_t vec;
  PyObject *db_spl;

  if (!PyArg_ParseTuple (args, "O:db_spl", &input)) {
    return NULL;
  }

  if (input == NULL) {
    return NULL;
  }

  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    return NULL;
  }

  db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
  if (db_spl == NULL) {
    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
    return NULL;
  }

  return db_spl;
}

PyObject *
Py_aubio_silence_detection(PyObject *self, PyObject *args)
{
  PyObject *input;
  fvec_t vec;
  PyObject *silence_detection;
  smpl_t threshold;

  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) {
    return NULL;
  }

  if (input == NULL) {
    return NULL;
  }

  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    return NULL;
  }

  silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
  if (silence_detection == NULL) {
    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
    return NULL;
  }

  return silence_detection;
}

PyObject *
Py_aubio_level_detection(PyObject *self, PyObject *args)
{
  PyObject *input;
  fvec_t vec;
  PyObject *level_detection;
  smpl_t threshold;

  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) {
    return NULL;
  }

  if (input == NULL) {
    return NULL;
  }

  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    return NULL;
  }

  level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
  if (level_detection == NULL) {
    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
    return NULL;
  }

  return level_detection;
}