summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2013-06-07 16:33:53 +0200
committerJohn Glover <j@johnglover.net>2013-06-07 16:33:53 +0200
commit5fa3a7b126c169bd5c3607cbbd503b002093e2ca (patch)
tree1e919cbcf882993b99985bce44ef873ff41f9c49 /src
parentd60bbc935a1c7137c766792bf569ea7d6800fba9 (diff)
downloadsimpl-5fa3a7b126c169bd5c3607cbbd503b002093e2ca.tar.gz
simpl-5fa3a7b126c169bd5c3607cbbd503b002093e2ca.tar.bz2
simpl-5fa3a7b126c169bd5c3607cbbd503b002093e2ca.zip
Fix memory leaks in partial tracking processes
Diffstat (limited to 'src')
-rw-r--r--src/simpl/base.cpp44
-rw-r--r--src/simpl/base.h3
-rw-r--r--src/simpl/partial_tracking.cpp79
-rw-r--r--src/simpl/partial_tracking.h10
-rw-r--r--src/simpl/peak_detection.cpp1
5 files changed, 73 insertions, 64 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp
index 248bd06..d56cdd3 100644
--- a/src/simpl/base.cpp
+++ b/src/simpl/base.cpp
@@ -52,7 +52,7 @@ Frame::Frame(int frame_size, bool alloc_memory) {
Frame::~Frame() {
clear_peaks();
- _partials.clear();
+ clear_partials();
for(int i = 0; i < _peaks.size(); i++) {
if(_peaks[i]) {
@@ -61,6 +61,13 @@ Frame::~Frame() {
}
}
+ for(int i = 0; i < _partials.size(); i++) {
+ if(_partials[i]) {
+ delete _partials[i];
+ _partials[i] = NULL;
+ }
+ }
+
if(_alloc_memory) {
destroy_arrays();
}
@@ -71,12 +78,12 @@ void Frame::init() {
_max_peaks = 100;
_num_partials = 0;
_max_partials = 100;
- _partials.resize(_max_partials);
_audio = NULL;
_synth = NULL;
_residual = NULL;
_synth_residual = NULL;
resize_peaks(_max_peaks);
+ resize_partials(_max_partials);
}
void Frame::create_arrays() {
@@ -135,6 +142,23 @@ void Frame::resize_peaks(int new_num_peaks) {
}
}
+void Frame::resize_partials(int new_num_partials) {
+ clear_partials();
+
+ for(int i = 0; i < _partials.size(); i++) {
+ if(_partials[i]) {
+ delete _partials[i];
+ _partials[i] = NULL;
+ }
+ }
+
+ _partials.resize(new_num_partials);
+
+ for(int i = 0; i < _partials.size(); i++) {
+ _partials[i] = new Peak();
+ }
+}
+
void Frame::clear() {
clear_peaks();
clear_partials();
@@ -156,6 +180,11 @@ void Frame::clear_peaks() {
void Frame::clear_partials() {
_num_partials = 0;
+ for(int i = 0; i < _partials.size(); i++) {
+ if(_partials[i]) {
+ _partials[i]->reset();
+ }
+ }
}
void Frame::clear_synth() {
@@ -250,7 +279,7 @@ void Frame::max_partials(int new_max_partials) {
" of partials, some existing data was lost.\n");
}
- _partials.resize(_max_partials);
+ resize_partials(_max_partials);
}
void Frame::add_partial(Peak* peak) {
@@ -265,6 +294,15 @@ void Frame::add_partial(Peak* peak) {
_num_partials++;
}
+void Frame::add_partial(sample amplitude, sample frequency,
+ sample phase, sample bandwidth) {
+ _partials[_num_partials]->amplitude = amplitude;
+ _partials[_num_partials]->frequency = frequency;
+ _partials[_num_partials]->phase = phase;
+ _partials[_num_partials]->bandwidth = bandwidth;
+ _num_partials++;
+}
+
Peak* Frame::partial(int partial_number) {
return _partials[partial_number];
}
diff --git a/src/simpl/base.h b/src/simpl/base.h
index 97f75e7..483912c 100644
--- a/src/simpl/base.h
+++ b/src/simpl/base.h
@@ -69,6 +69,7 @@ class Frame {
void create_synth_arrays();
void destroy_synth_arrays();
void resize_peaks(int new_num_peaks);
+ void resize_partials(int new_num_partials);
public:
Frame();
@@ -96,6 +97,8 @@ class Frame {
int max_partials();
void max_partials(int new_max_partials);
void add_partial(Peak* peak);
+ void add_partial(sample amplitude, sample frequency,
+ sample phase, sample bandwidth);
Peak* partial(int partial_number);
void partial(int partial_number, Peak* peak);
diff --git a/src/simpl/partial_tracking.cpp b/src/simpl/partial_tracking.cpp
index 81644b0..bb22709 100644
--- a/src/simpl/partial_tracking.cpp
+++ b/src/simpl/partial_tracking.cpp
@@ -55,14 +55,7 @@ void PartialTracking::max_gap(int new_max_gap) {
}
// Streamable (real-time) partial-tracking.
-Peaks PartialTracking::update_partials(Frame* frame) {
- Peaks peaks;
-
- for(int i = 0; i < peaks.size(); i++) {
- frame->add_partial(peaks[i]);
- }
-
- return peaks;
+void PartialTracking::update_partials(Frame* frame) {
}
// Find partials from the sinusoidal peaks in a list of Frames.
@@ -113,8 +106,7 @@ void MQPartialTracking::max_partials(int new_max_partials) {
_mq_params.max_peaks = _max_partials;
}
-Peaks MQPartialTracking::update_partials(Frame* frame) {
- Peaks peaks;
+void MQPartialTracking::update_partials(Frame* frame) {
int num_peaks = _max_partials;
if(num_peaks > frame->num_peaks()) {
num_peaks = frame->num_peaks();
@@ -138,26 +130,21 @@ Peaks MQPartialTracking::update_partials(Frame* frame) {
int num_partials = 0;
while(partials && partials->peak && (num_partials < _max_partials)) {
- Peak* p = new Peak();
- p->amplitude = partials->peak->amplitude;
- p->frequency = partials->peak->frequency;
- p->phase = partials->peak->phase;
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(partials->peak->amplitude,
+ partials->peak->frequency,
+ partials->peak->phase,
+ 0.0);
partials = partials->next;
num_partials++;
}
for(int i = num_partials; i < _max_partials; i++) {
- Peak* p = new Peak();
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(0.0, 0.0, 0.0, 0.0);
}
delete_peak_list(_prev_peak_list);
_prev_peak_list = _peak_list;
- return peaks;
}
@@ -337,7 +324,7 @@ void SMSPartialTracking::clean_tracks(bool new_clean_tracks) {
}
}
-Peaks SMSPartialTracking::update_partials(Frame* frame) {
+void SMSPartialTracking::update_partials(Frame* frame) {
int num_peaks = _max_partials;
if(num_peaks > frame->num_peaks()) {
num_peaks = frame->num_peaks();
@@ -360,18 +347,12 @@ Peaks SMSPartialTracking::update_partials(Frame* frame) {
sms_findPartials(&_data, &_analysis_params);
// get partials from SMSData object
- Peaks peaks;
-
for(int i = 0; i < _data.nTracks; i++) {
- Peak* p = new Peak();
- p->amplitude = _data.pFSinAmp[i];
- p->frequency = _data.pFSinFreq[i];
- p->phase = _data.pFSinPha[i];
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(_data.pFSinAmp[i],
+ _data.pFSinFreq[i],
+ _data.pFSinPha[i],
+ 0.0);
}
-
- return peaks;
}
// ---------------------------------------------------------------------------
@@ -446,7 +427,7 @@ void SndObjPartialTracking::max_partials(int new_max_partials) {
reset();
}
-Peaks SndObjPartialTracking::update_partials(Frame* frame) {
+void SndObjPartialTracking::update_partials(Frame* frame) {
int num_peaks = _max_partials;
if(num_peaks > frame->num_peaks()) {
num_peaks = frame->num_peaks();
@@ -465,24 +446,17 @@ Peaks SndObjPartialTracking::update_partials(Frame* frame) {
_analysis->PartialTracking();
int num_partials = _analysis->GetTracks();
- Peaks peaks;
for(int i = 0; i < num_partials; i++) {
- Peak* p = new Peak();
- p->amplitude = _analysis->Output(i * 3);
- p->frequency = _analysis->Output((i * 3) + 1);
- p->phase = _analysis->Output((i * 3) + 2);
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(_analysis->Output(i * 3),
+ _analysis->Output((i * 3) + 1),
+ _analysis->Output((i * 3) + 2),
+ 0.0);
}
for(int i = num_partials; i < _max_partials; i++) {
- Peak* p = new Peak();
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(0.0, 0.0, 0.0, 0.0);
}
-
- return peaks;
}
// ---------------------------------------------------------------------------
@@ -540,14 +514,12 @@ void LorisPartialTracking::max_partials(int new_max_partials) {
reset();
}
-Peaks LorisPartialTracking::update_partials(Frame* frame) {
+void LorisPartialTracking::update_partials(Frame* frame) {
int num_peaks = frame->num_peaks();
if(num_peaks > _max_partials) {
num_peaks = _max_partials;
}
- Peaks peaks;
-
_analyzer->peaks.clear();
for(int i = 0; i < num_peaks; i++) {
Loris::Breakpoint bp = Loris::Breakpoint(frame->peak(i)->frequency,
@@ -561,14 +533,9 @@ Peaks LorisPartialTracking::update_partials(Frame* frame) {
int num_partials = _analyzer->partials.size();
for(int i = 0; i < num_partials; i++) {
- Peak* p = new Peak();
- p->amplitude = _analyzer->partials[i].amplitude();
- p->frequency = _analyzer->partials[i].frequency();
- p->phase = _analyzer->partials[i].phase();
- p->bandwidth = _analyzer->partials[i].bandwidth();
- peaks.push_back(p);
- frame->add_partial(p);
+ frame->add_partial(_analyzer->partials[i].amplitude(),
+ _analyzer->partials[i].frequency(),
+ _analyzer->partials[i].phase(),
+ _analyzer->partials[i].bandwidth());
}
-
- return peaks;
}
diff --git a/src/simpl/partial_tracking.h b/src/simpl/partial_tracking.h
index b41bc9a..fd143ee 100644
--- a/src/simpl/partial_tracking.h
+++ b/src/simpl/partial_tracking.h
@@ -59,7 +59,7 @@ class PartialTracking {
int max_gap();
virtual void max_gap(int new_max_gap);
- virtual Peaks update_partials(Frame* frame);
+ virtual void update_partials(Frame* frame);
virtual Frames find_partials(Frames frames);
};
@@ -78,7 +78,7 @@ class MQPartialTracking : public PartialTracking {
void reset();
using PartialTracking::max_partials;
void max_partials(int new_max_partials);
- Peaks update_partials(Frame* frame);
+ void update_partials(Frame* frame);
};
// ---------------------------------------------------------------------------
@@ -112,7 +112,7 @@ class SMSPartialTracking : public PartialTracking {
void min_good_frames(int new_min_good_frames);
bool clean_tracks();
void clean_tracks(bool new_clean_tracks);
- Peaks update_partials(Frame* frame);
+ void update_partials(Frame* frame);
};
@@ -135,7 +135,7 @@ class SndObjPartialTracking : public PartialTracking {
void reset();
using PartialTracking::max_partials;
void max_partials(int new_max_partials);
- Peaks update_partials(Frame* frame);
+ void update_partials(Frame* frame);
};
// ---------------------------------------------------------------------------
@@ -165,7 +165,7 @@ class LorisPartialTracking : public PartialTracking {
void reset();
using PartialTracking::max_partials;
void max_partials(int new_max_partials);
- Peaks update_partials(Frame* frame);
+ void update_partials(Frame* frame);
};
diff --git a/src/simpl/peak_detection.cpp b/src/simpl/peak_detection.cpp
index f142757..08d343b 100644
--- a/src/simpl/peak_detection.cpp
+++ b/src/simpl/peak_detection.cpp
@@ -27,6 +27,7 @@ void PeakDetection::clear() {
for(int i = 0; i < _frames.size(); i++) {
if(_frames[i]) {
delete _frames[i];
+ _frames[i] = NULL;
}
}