[aimc] r297 committed - Fix memory leak in CARFAC....

0 views
Skip to first unread message

ai...@googlecode.com

unread,
Jun 11, 2013, 5:42:07 PM6/11/13
to aimc...@googlegroups.com
Revision: 297
Author: ro...@google.com
Date: Tue Jun 11 14:41:53 2013
Log: Fix memory leak in CARFAC.

Also get rid of most uses of auto, which tend to hurt readability
unless the type name is particularly long, especially when it masks
pointers.


http://code.google.com/p/aimc/source/detail?r=297

Modified:
/trunk/carfac/carfac.cc
/trunk/carfac/carfac.h
/trunk/carfac/carfac_output.cc
/trunk/carfac/carfac_test.cc
/trunk/carfac/ear.cc

=======================================
--- /trunk/carfac/carfac.cc Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/carfac.cc Tue Jun 11 14:41:53 2013
@@ -35,6 +35,12 @@
const AGCParams& agc_params) {
Reset(num_ears, sample_rate, car_params, ihc_params, agc_params);
}
+
+CARFAC::~CARFAC() {
+ for (Ear* ear : ears_) {
+ delete ear;
+ }
+}

void CARFAC::Reset(const int num_ears, const FPType sample_rate,
const CARParams& car_params, const IHCParams&
ihc_params,
@@ -118,12 +124,12 @@
if (mix_coeff > 0) {
ArrayX stage_state;
ArrayX this_stage_values = ArrayX::Zero(num_channels_);
- for (const auto& ear : ears_) {
+ for (Ear* ear : ears_) {
stage_state = ear->agc_memory(stage);
this_stage_values += stage_state;
}
this_stage_values /= num_ears_;
- for (const auto& ear : ears_) {
+ for (Ear* ear : ears_) {
stage_state = ear->agc_memory(stage);
ear->set_agc_memory(stage, stage_state + mix_coeff *
(this_stage_values - stage_state));
@@ -134,7 +140,7 @@
}

void CARFAC::CloseAGCLoop() {
- for (auto& ear : ears_) {
+ for (Ear* ear : ears_) {
ArrayX undamping = 1 - ear->agc_memory(0);
// This updates the target stage gain for the new damping.
ear->set_dzb_memory((ear->zr_coeffs() * undamping - ear->zb_memory()) /
=======================================
--- /trunk/carfac/carfac.h Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/carfac.h Tue Jun 11 14:41:53 2013
@@ -47,6 +47,7 @@
CARFAC(const int num_ears, const FPType sample_rate,
const CARParams& car_params, const IHCParams& ihc_params,
const AGCParams& agc_params);
+ ~CARFAC();

void Reset(const int num_ears, const FPType sample_rate,
const CARParams& car_params, const IHCParams& ihc_params,
=======================================
--- /trunk/carfac/carfac_output.cc Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/carfac_output.cc Tue Jun 11 14:41:53 2013
@@ -36,25 +36,25 @@
void CARFACOutput::AppendOutput(const vector<Ear*>& ears) {
if (store_nap_) {
nap_.push_back(vector<ArrayX>());
- for (const auto& ear : ears) {
+ for (Ear* ear : ears) {
nap_.back().push_back(ear->ihc_out());
}
}
if (store_ohc_) {
ohc_.push_back(vector<ArrayX>());
- for (const auto& ear : ears) {
+ for (Ear* ear : ears) {
ohc_.back().push_back(ear->za_memory());
}
}
if (store_agc_) {
agc_.push_back(vector<ArrayX>());
- for (const auto& ear : ears) {
+ for (Ear* ear : ears) {
agc_.back().push_back(ear->zb_memory());
}
}
if (store_bm_) {
bm_.push_back(vector<ArrayX>());
- for (const auto& ear : ears) {
+ for (Ear* ear : ears) {
bm_.back().push_back(ear->zy_memory());
}
}
=======================================
--- /trunk/carfac/carfac_test.cc Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/carfac_test.cc Tue Jun 11 14:41:53 2013
@@ -86,13 +86,13 @@

// This loads a vector of ArrayXs from multi-column text files.
vector<ArrayX> Load2dTestData(const string filename, const int rows,
- const int columns) {
+ const int columns) {
string fullfile = kTestSourceDir + filename;
ifstream file(fullfile.c_str());
FPType myarray[rows][columns];
vector<ArrayX> output;
output.resize(rows);
- for (auto& timepoint : output) {
+ for (ArrayX& timepoint : output) {
timepoint.resize(columns);
}
if (file.is_open()) {
=======================================
--- /trunk/carfac/ear.cc Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/ear.cc Tue Jun 11 14:41:53 2013
@@ -73,7 +73,7 @@
void Ear::ResetAGCState() {
int n_agc_stages = agc_coeffs_.size();
agc_state_.resize(n_agc_stages);
- for (auto& stage_state : agc_state_) {
+ for (AGCState& stage_state : agc_state_) {
stage_state.decim_phase = 0;
stage_state.agc_memory.setZero(num_channels_);
stage_state.input_accum.setZero(num_channels_);
@@ -175,8 +175,8 @@

bool Ear::AGCRecurse(const int stage, ArrayX agc_in) {
bool updated = true;
- const auto& agc_coeffs = agc_coeffs_[stage];
- auto& agc_state = agc_state_[stage];
+ const AGCCoeffs& agc_coeffs = agc_coeffs_[stage];
+ AGCState& agc_state = agc_state_[stage];
// This is the decim factor for this stage, relative to input or prev.
stage:
int decim = agc_coeffs.decimation;
// This is the decim phase of this stage (do work on phase 0 only):
Reply all
Reply to author
Forward
0 new messages