diff options
author | John Glover <j@johnglover.net> | 2012-07-02 23:20:02 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-07-02 23:20:02 +0100 |
commit | 6b5c582958478888809386d726d3bd1a1447b45c (patch) | |
tree | 0fa83cb18aa441ec30da80d8edc8b954f0cfe9f8 | |
parent | d08f3f518e16f1c1260e9e6398ed713b14571faf (diff) | |
download | simpl-6b5c582958478888809386d726d3bd1a1447b45c.tar.gz simpl-6b5c582958478888809386d726d3bd1a1447b45c.tar.bz2 simpl-6b5c582958478888809386d726d3bd1a1447b45c.zip |
[partial_tracking] Bug fix: check partial array sizes correctly, initialise values to 0.
-rw-r--r-- | src/simpl/partial_tracking.cpp | 27 | ||||
-rw-r--r-- | src/simpl/partial_tracking.h | 1 |
2 files changed, 15 insertions, 13 deletions
diff --git a/src/simpl/partial_tracking.cpp b/src/simpl/partial_tracking.cpp index 22832c4..4c4938c 100644 --- a/src/simpl/partial_tracking.cpp +++ b/src/simpl/partial_tracking.cpp @@ -100,7 +100,6 @@ SMSPartialTracking::SMSPartialTracking() { sms_fillHeader(&_header, &_analysis_params); sms_allocFrameH(&_header, &_data); - _num_peaks = 100; init_peaks(); } @@ -125,9 +124,13 @@ void SMSPartialTracking::init_peaks() { delete [] _peak_phase; } - _peak_amplitude = new sample[_num_peaks]; - _peak_frequency = new sample[_num_peaks]; - _peak_phase = new sample[_num_peaks]; + _peak_amplitude = new sample[_max_partials]; + _peak_frequency = new sample[_max_partials]; + _peak_phase = new sample[_max_partials]; + + memset(_peak_amplitude, 0.0, sizeof(sample) * _max_partials); + memset(_peak_frequency, 0.0, sizeof(sample) * _max_partials); + memset(_peak_phase, 0.0, sizeof(sample) * _max_partials); } void SMSPartialTracking::max_partials(int new_max_partials) { @@ -136,7 +139,6 @@ void SMSPartialTracking::max_partials(int new_max_partials) { sms_freeAnalysis(&_analysis_params); sms_freeFrame(&_data); - // sms_initAnalParams(&_analysis_params); _analysis_params.maxPeaks = _max_partials; _analysis_params.nTracks = _max_partials; _analysis_params.nGuides = _max_partials; @@ -147,20 +149,21 @@ void SMSPartialTracking::max_partials(int new_max_partials) { } Peaks SMSPartialTracking::update_partials(Frame* frame) { - if(_num_peaks != frame->num_peaks()) { - _num_peaks = frame->num_peaks(); - init_peaks(); + int num_peaks = _max_partials; + if(num_peaks > frame->num_peaks()) { + num_peaks = frame->num_peaks(); } // set peaks in SMSAnalysisParams object - for(int i = 0; i < _num_peaks; i++) { + for(int i = 0; i < num_peaks; i++) { _peak_amplitude[i] = frame->peak(i)->amplitude; _peak_frequency[i] = frame->peak(i)->frequency; _peak_phase[i] = frame->peak(i)->phase; } - sms_setPeaks(&_analysis_params, _num_peaks, _peak_amplitude, - _num_peaks, _peak_frequency, - _num_peaks, _peak_phase); + + sms_setPeaks(&_analysis_params, _max_partials, _peak_amplitude, + _max_partials, _peak_frequency, + _max_partials, _peak_phase); // SMS partial tracking sms_findPartials(&_data, &_analysis_params); diff --git a/src/simpl/partial_tracking.h b/src/simpl/partial_tracking.h index e6f08d2..964d959 100644 --- a/src/simpl/partial_tracking.h +++ b/src/simpl/partial_tracking.h @@ -55,7 +55,6 @@ class SMSPartialTracking : public PartialTracking { SMSAnalysisParams _analysis_params; SMSHeader _header; SMSData _data; - int _num_peaks; sample* _peak_amplitude; sample* _peak_frequency; sample* _peak_phase; |