summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-03-16 17:08:58 +0000
committerJohn Glover <j@johnglover.net>2012-03-16 17:08:58 +0000
commitd9a7ad89d8a7554898eedbd72113eb7e461906ae (patch)
tree0f9f06f06e0bd9349a990ff76cd5aa8d42bf36de
parent165c524ecfc67529e51b59fe196d2abc003677a9 (diff)
downloadsimpl-d9a7ad89d8a7554898eedbd72113eb7e461906ae.tar.gz
simpl-d9a7ad89d8a7554898eedbd72113eb7e461906ae.tar.bz2
simpl-d9a7ad89d8a7554898eedbd72113eb7e461906ae.zip
add Cython base.Peak class
-rw-r--r--simpl/base.pyx27
-rw-r--r--tests/test_base.py6
2 files changed, 30 insertions, 3 deletions
diff --git a/simpl/base.pyx b/simpl/base.pyx
index d33951b..6cb4fa8 100644
--- a/simpl/base.pyx
+++ b/simpl/base.pyx
@@ -6,6 +6,12 @@ dtype = np.float64
ctypedef np.double_t dtype_t
cdef extern from "../src/simpl/base.h" namespace "simpl":
+ cdef cppclass c_Peak "simpl::Peak":
+ c_Peak()
+ double amplitude
+ double frequency
+ double phase
+
cdef cppclass c_Frame "simpl::Frame":
c_Frame()
c_Frame(int frame_size)
@@ -40,6 +46,23 @@ cdef extern from "../src/simpl/base.h" namespace "simpl":
void synth_residual(double* new_synth_residual)
double* synth_residual()
+cdef class Peak:
+ cdef c_Peak *thisptr
+ def __cinit__(self): self.thisptr = new c_Peak()
+ def __dealloc__(self): del self.thisptr
+
+ property amplitude:
+ def __get__(self): return self.thisptr.amplitude
+ def __set__(self, double x): self.thisptr.amplitude = x
+
+ property frequency:
+ def __get__(self): return self.thisptr.frequency
+ def __set__(self, double x): self.thisptr.frequency = x
+
+ property phase:
+ def __get__(self): return self.thisptr.phase
+ def __set__(self, double x): self.thisptr.phase = x
+
cdef class Frame:
cdef c_Frame *thisptr
@@ -49,8 +72,7 @@ cdef class Frame:
else:
self.thisptr = new c_Frame()
- def __dealloc__(self):
- del self.thisptr
+ def __dealloc__(self): del self.thisptr
property size:
def __get__(self): return self.thisptr.size()
@@ -87,4 +109,3 @@ cdef class Frame:
return np.PyArray_SimpleNewFromData(1, shape, np.NPY_DOUBLE, self.thisptr.synth_residual())
def __set__(self, np.ndarray[dtype_t, ndim=1] a):
self.thisptr.synth_residual(<double*> a.data)
-
diff --git a/tests/test_base.py b/tests/test_base.py
index c906f31..4dac897 100644
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -23,3 +23,9 @@ class TestFrame(object):
a = np.random.rand(N)
f.synth_residual = a
assert np.all(f.synth_residual == a)
+
+ def test_peak(self):
+ p = base.Peak()
+ p.amplitude = 0.5
+ p.frequency = 220.0
+ p.phase = 0.0