diff options
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | src/simpl/base.cpp | 92 | ||||
-rw-r--r-- | src/simpl/base.h | 16 | ||||
-rw-r--r-- | src/simpl/peak_detection.cpp | 11 |
4 files changed, 79 insertions, 49 deletions
@@ -2,6 +2,7 @@ Icon? Thumbs.db *.swp +*.wav # Distutils/pip files build @@ -13,14 +14,6 @@ build_release *.o *.so *.os -*_wrap.c -*_wrap.cc -*_wrap.cpp -*_wrap.h - -# Files generated by SWIG -simpl/simplsndobj.py -simpl/simplsms.py # Files generated by Cython simpl/base.cpp diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp index 1751dd5..01e18b2 100644 --- a/src/simpl/base.cpp +++ b/src/simpl/base.cpp @@ -12,39 +12,11 @@ Peak::Peak() { frequency = 0.0; phase = 0.0; bandwidth = 0.0; - next_peak = NULL; - previous_peak = NULL; - partial_id = 0; - partial_position = 0; - frame_number = 0; } Peak::~Peak() { } -// Returns true iff this peak is unmatched in the given direction, and has positive amplitude -bool Peak::is_free(const string direction) { - if(amplitude <= 0.0) { - return false; - } - - if(direction == "forwards") { - if(next_peak != NULL) { - return false; - } - } - else if(direction == "backwards") { - if(previous_peak != NULL) { - return false; - } - } - else { - return false; - } - - return true; -} - // --------------------------------------------------------------------------- // Partial @@ -275,6 +247,22 @@ void Frame::audio(sample* new_audio) { } } +void Frame::audio(sample* new_audio, int size) { + // this should only be called if the Frame is managing the memory + // for the sample arrays + if(!_alloc_memory) { + throw Exception(std::string("Memory not managed by Frame.")); + } + + // copy size should also be less than or equal to the current frame size + if(size > _size) { + throw Exception(std::string("Specified copy size is too large, " + "it must be less than the Frame size.")); + } + + memcpy(_audio, new_audio, sizeof(sample) * size); +} + sample* Frame::audio() { return _audio; } @@ -288,6 +276,22 @@ void Frame::synth(sample* new_synth) { } } +void Frame::synth(sample* new_synth, int size) { + // this should only be called if the Frame is managing the memory + // for the sample arrays + if(!_alloc_memory) { + throw Exception(std::string("Memory not managed by Frame.")); + } + + // copy size should also be less than or equal to the current frame synth size + if(size > _synth_size) { + throw Exception(std::string("Specified copy size is too large, " + "it must be less than the Frame synth size.")); + } + + memcpy(_synth, new_synth, sizeof(sample) * size); +} + sample* Frame::synth() { return _synth; } @@ -301,6 +305,22 @@ void Frame::residual(sample* new_residual) { } } +void Frame::residual(sample* new_residual, int size) { + // this should only be called if the Frame is managing the memory + // for the sample arrays + if(!_alloc_memory) { + throw Exception(std::string("Memory not managed by Frame.")); + } + + // copy size should also be less than or equal to the current frame size + if(size > _size) { + throw Exception(std::string("Specified copy size is too large, " + "it must be less than the Frame size.")); + } + + memcpy(_residual, new_residual, sizeof(sample) * size); +} + sample* Frame::residual() { return _residual; } @@ -314,6 +334,22 @@ void Frame::synth_residual(sample* new_synth_residual) { } } +void Frame::synth_residual(sample* new_synth_residual, int size) { + // this should only be called if the Frame is managing the memory + // for the sample arrays + if(!_alloc_memory) { + throw Exception(std::string("Memory not managed by Frame.")); + } + + // copy size should also be less than or equal to the current frame synth size + if(size > _synth_size) { + throw Exception(std::string("Specified copy size is too large, " + "it must be less than the Frame synth size.")); + } + + memcpy(_synth_residual, new_synth_residual, sizeof(sample) * size); +} + sample* Frame::synth_residual() { return _synth_residual; } diff --git a/src/simpl/base.h b/src/simpl/base.h index 8d7138c..9e04ef7 100644 --- a/src/simpl/base.h +++ b/src/simpl/base.h @@ -4,7 +4,7 @@ #include <vector> #include <string> -using namespace std; +#include "exceptions.h" namespace simpl { @@ -23,19 +23,9 @@ class Peak { sample frequency; sample phase; sample bandwidth; - Peak* next_peak; - Peak* previous_peak; - int partial_id; - int partial_position; - int frame_number; Peak(); ~Peak(); - - bool is_start_of_partial() { - return previous_peak == NULL; - }; - bool is_free(const string direction = string("forwards")); }; typedef std::vector<Peak*> Peaks; @@ -128,12 +118,16 @@ class Frame { int synth_size(); void synth_size(int new_size); void audio(sample* new_audio); + void audio(sample* new_audio, int size); sample* audio(); void synth(sample* new_synth); + void synth(sample* new_synth, int size); sample* synth(); void residual(sample* new_residual); + void residual(sample* new_residual, int size); sample* residual(); void synth_residual(sample* new_synth_residual); + void synth_residual(sample* new_synth_residual, int size); sample* synth_residual(); }; diff --git a/src/simpl/peak_detection.cpp b/src/simpl/peak_detection.cpp index ff66278..0f28da3 100644 --- a/src/simpl/peak_detection.cpp +++ b/src/simpl/peak_detection.cpp @@ -143,8 +143,15 @@ Frames PeakDetection::find_peaks(int audio_size, sample* audio) { } // get the next frame - Frame* f = new Frame(_frame_size); - f->audio(&(audio[pos])); + Frame* f = new Frame(_frame_size, true); + + if((int)pos <= (audio_size - _frame_size)) { + f->audio(&(audio[pos]), _frame_size); + } + else { + f->audio(&(audio[pos]), audio_size - pos); + } + f->max_peaks(_max_peaks); // find peaks |