diff options
-rw-r--r-- | simpl/synthesis.pyx | 1 | ||||
-rw-r--r-- | src/simpl/base.cpp | 23 | ||||
-rw-r--r-- | src/simpl/base.h | 2 | ||||
-rw-r--r-- | src/simpl/synthesis.cpp | 5 | ||||
-rw-r--r-- | tests/test_synthesis.cpp | 8 |
5 files changed, 25 insertions, 14 deletions
diff --git a/simpl/synthesis.pyx b/simpl/synthesis.pyx index 8e4a050..fd945ed 100644 --- a/simpl/synthesis.pyx +++ b/simpl/synthesis.pyx @@ -44,6 +44,7 @@ cdef class Synthesis: cdef np.ndarray[dtype_t, ndim=1] output = np.zeros(len(frames) * size) for i in range(len(frames)): frames[i].synth = np.zeros(size) + frames[i].synth_size = size self.synth_frame(frames[i]) output[i * size:(i + 1) * size] = frames[i].synth return output diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp index 9683df3..c97e8bc 100644 --- a/src/simpl/base.cpp +++ b/src/simpl/base.cpp @@ -63,20 +63,27 @@ void Frame::init() { void Frame::create_arrays() { _audio = new sample[_size]; - _synth = new sample[_synth_size]; _residual = new sample[_size]; - _synth_residual = new sample[_synth_size]; - memset(_audio, 0.0, sizeof(sample) * _size); - memset(_synth, 0.0, sizeof(sample) * _synth_size); memset(_residual, 0.0, sizeof(sample) * _size); - memset(_synth_residual, 0.0, sizeof(sample) * _synth_size); + create_synth_arrays(); } void Frame::destroy_arrays() { delete [] _audio; - delete [] _synth; delete [] _residual; + destroy_synth_arrays(); +} + +void Frame::create_synth_arrays() { + _synth = new sample[_synth_size]; + _synth_residual = new sample[_synth_size]; + memset(_synth, 0.0, sizeof(sample) * _synth_size); + memset(_synth_residual, 0.0, sizeof(sample) * _synth_size); +} + +void Frame::destroy_synth_arrays() { + delete [] _synth; delete [] _synth_residual; } @@ -214,8 +221,8 @@ void Frame::synth_size(int new_size) { _synth_size = new_size; if(_alloc_memory) { - destroy_arrays(); - create_arrays(); + destroy_synth_arrays(); + create_synth_arrays(); } } diff --git a/src/simpl/base.h b/src/simpl/base.h index 5a3bf5b..cfa139c 100644 --- a/src/simpl/base.h +++ b/src/simpl/base.h @@ -60,6 +60,8 @@ class Frame { bool _alloc_memory; void create_arrays(); void destroy_arrays(); + void create_synth_arrays(); + void destroy_synth_arrays(); public: Frame(); diff --git a/src/simpl/synthesis.cpp b/src/simpl/synthesis.cpp index 5784522..3f48c78 100644 --- a/src/simpl/synthesis.cpp +++ b/src/simpl/synthesis.cpp @@ -51,10 +51,7 @@ void Synthesis::synth_frame(Frame* frame) { Frames Synthesis::synth(Frames frames) { for(int i = 0; i < frames.size(); i++) { - sample* synth_audio = new sample[_frame_size]; - memset(synth_audio, 0.0, sizeof(sample) * _frame_size); - frames[i]->synth(synth_audio); - frames[i]->synth_size(_frame_size); + frames[i]->synth_size(_hop_size); synth_frame(frames[i]); } return frames; diff --git a/tests/test_synthesis.cpp b/tests/test_synthesis.cpp index f4d215d..50ca6ed 100644 --- a/tests/test_synthesis.cpp +++ b/tests/test_synthesis.cpp @@ -39,8 +39,12 @@ protected: frames = synth->synth(frames); for(int i = 0; i < frames.size(); i++) { - CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); - CPPUNIT_ASSERT(frames[i]->num_partials() > 0); + // if Loris thinPeaks is used, final frame will have no peaks + // so don't check it + if(i < frames.size() - 1) { + CPPUNIT_ASSERT(frames[i]->num_peaks() > 0); + CPPUNIT_ASSERT(frames[i]->num_partials() > 0); + } double energy = 0.f; for(int j = 0; j < synth->hop_size(); j++) { |