History

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

Paul Brossier committed 10 years ago

Commit ede5d381 parent ee092a84 files · +54 −33Browse files

Showing the changes to python/ext (4 of 4 files). Show all

Unified · Split

4 files
  1. python/ext/aubio-types.h +4 −0
  2. python/ext/aubioproxy.c +12 −0
  3. python/ext/py-cvec.c +18 −22
  4. python/ext/py-fft.c +20 −11
python/ext/aubio-types.h+4−0
@@ -52,6 +52,10 @@ · 51 unmodified lines
52 52
53extern PyTypeObject Py_cvecType;53extern PyTypeObject Py_cvecType;
54 54
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
55// defined in aubio-proxy.c59// defined in aubio-proxy.c
56extern PyObject *PyAubio_CFvecToArray (fvec_t * self);60extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
57extern int PyAubio_ArrayToCFvec (PyObject * self, fvec_t *out);61extern int PyAubio_ArrayToCFvec (PyObject * self, fvec_t *out);
python/ext/aubioproxy.c+12−0
@@ -1,5 +1,17 @@
1#include "aubio-types.h"1#include "aubio-types.h"
2 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}
14
3PyObject *15PyObject *
4PyAubio_CFvecToArray (fvec_t * self)16PyAubio_CFvecToArray (fvec_t * self)
5{17{
python/ext/py-cvec.c+18−22
@@ -21,6 +21,17 @@ typedef struct · 20 unmodified lines
21 21
22static char Py_cvec_doc[] = "cvec object";22static char Py_cvec_doc[] = "cvec object";
23 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}
34
24PyObject *35PyObject *
25PyAubio_CCvecToPyCvec (cvec_t * input) {36PyAubio_CCvecToPyCvec (cvec_t * input) {
26 if (input == NULL) {37 if (input == NULL) {
@@ -39,14 +50,6 @@ int · 12 unmodified lines
39PyAubio_PyCvecToCCvec (PyObject *input, cvec_t *i) {50PyAubio_PyCvecToCCvec (PyObject *input, cvec_t *i) {
40 if (PyObject_TypeCheck (input, &Py_cvecType)) {51 if (PyObject_TypeCheck (input, &Py_cvecType)) {
41 Py_cvec * in = (Py_cvec *)input;52 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 }
50 i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0);53 i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0);
51 i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0);54 i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0);
52 i->length = ((Py_cvec*)input)->length;55 i->length = ((Py_cvec*)input)->length;
@@ -91,16 +94,17 @@ Py_cvec_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 38 unmodified lines
91static int94static int
92Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds)95Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds)
93{96{
94 self->norm = NULL;97 npy_intp dims[] = { self->length, 1 };
95 self->phas = NULL;98 self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
99 self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
96 return 0;100 return 0;
97}101}
98 102
99static void103static void
100Py_cvec_del (Py_cvec * self)104Py_cvec_del (Py_cvec * self)
101{105{
102 Py_XDECREF(self->norm);106 Py_DECREF(self->norm);
103 Py_XDECREF(self->phas);107 Py_DECREF(self->phas);
104 Py_TYPE(self)->tp_free ((PyObject *) self);108 Py_TYPE(self)->tp_free ((PyObject *) self);
105}109}
106 110
@@ -134,11 +138,7 @@ fail: · 27 unmodified lines
134PyObject *138PyObject *
135Py_cvec_get_norm (Py_cvec * self, void *closure)139Py_cvec_get_norm (Py_cvec * self, void *closure)
136{140{
137 // if it norm hasn't been created, create it now141 // we want self->norm to still exist after our caller return it
138 if (self->norm == NULL) {
139 npy_intp dims[] = { self->length, 1 };
140 self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
141 }
142 Py_INCREF(self->norm);142 Py_INCREF(self->norm);
143 return (PyObject*)(self->norm);143 return (PyObject*)(self->norm);
144}144}
@@ -146,11 +146,7 @@ Py_cvec_get_norm (Py_cvec * self, void *closure) · 1 unmodified line
146PyObject *146PyObject *
147Py_cvec_get_phas (Py_cvec * self, void *closure)147Py_cvec_get_phas (Py_cvec * self, void *closure)
148{148{
149 // if it phas hasn't been created, create it now149 // we want self->phas to still exist after our caller return it
150 if (self->phas == NULL) {
151 npy_intp dims[] = { self->length, 1 };
152 self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0);
153 }
154 Py_INCREF(self->phas);150 Py_INCREF(self->phas);
155 return (PyObject *)(self->phas);151 return (PyObject *)(self->phas);
156}152}
python/ext/py-fft.c+20−11
@@ -11,8 +11,8 @@ typedef struct · 10 unmodified lines
11 fvec_t vecin;11 fvec_t vecin;
12 cvec_t cvecin;12 cvec_t cvecin;
13 // do / rdo output results13 // do / rdo output results
14 cvec_t *out;14 PyObject *doout;
15 fvec_t *rout;15 PyObject *rdoout;
16} Py_fft;16} Py_fft;
17 17
18static PyObject *18static PyObject *
@@ -57,8 +57,8 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 38 unmodified lines
57 return -1;57 return -1;
58 }58 }
59 59
60 self->out = new_cvec(self->win_s);60 self->doout = new_py_cvec(self->win_s);
61 self->rout = new_fvec(self->win_s);61 self->rdoout = new_py_fvec(self->win_s);
62 62
63 return 0;63 return 0;
64}64}
@@ -66,9 +66,9 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 1 unmodified line
66static void66static void
67Py_fft_del (Py_fft *self, PyObject *unused)67Py_fft_del (Py_fft *self, PyObject *unused)
68{68{
69 Py_XDECREF(self->doout);
70 Py_XDECREF(self->rdoout);
69 del_aubio_fft(self->o);71 del_aubio_fft(self->o);
70 del_cvec(self->out);
71 del_fvec(self->rout);
72 Py_TYPE(self)->tp_free((PyObject *) self);72 Py_TYPE(self)->tp_free((PyObject *) self);
73}73}
74 74
@@ -85,10 +85,14 @@ Py_fft_do(Py_fft * self, PyObject * args) · 10 unmodified lines
85 return NULL;85 return NULL;
86 }86 }
87 87
88 cvec_t c_out;
89 Py_INCREF(self->doout);
90 if (!PyAubio_PyCvecToCCvec(self->doout, &c_out)) {
91 return NULL;
92 }
88 // compute the function93 // compute the function
89 aubio_fft_do (((Py_fft *)self)->o, &(self->vecin), self->out);94 aubio_fft_do (self->o, &(self->vecin), &c_out);
90 // convert cvec to py_cvec95 return self->doout;
91 return PyAubio_CCvecToPyCvec(self->out);
92}96}
93 97
94static PyMemberDef Py_fft_members[] = {98static PyMemberDef Py_fft_members[] = {
@@ -110,9 +114,14 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 15 unmodified lines
110 return NULL;114 return NULL;
111 }115 }
112 116
117 fvec_t out;
118 Py_INCREF(self->rdoout);
119 if (!PyAubio_ArrayToCFvec(self->rdoout, &out) ) {
120 return NULL;
121 }
113 // compute the function122 // compute the function
114 aubio_fft_rdo (self->o, &(self->cvecin), self->rout);123 aubio_fft_rdo (self->o, &(self->cvecin), &out);
115 return PyAubio_CFvecToArray(self->rout);124 return self->rdoout;
116}125}
117 126
118static PyMethodDef Py_fft_methods[] = {127static PyMethodDef Py_fft_methods[] = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t