Mercurial > hg > aimc
changeset 648:1c2a5868f23a
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.
author | ronw@google.com |
---|---|
date | Tue, 11 Jun 2013 21:41:53 +0000 |
parents | 749b5aed61f6 |
children | 461d4374b6d9 |
files | carfac/carfac.cc carfac/carfac.h carfac/carfac_output.cc carfac/carfac_test.cc carfac/ear.cc |
diffstat | 5 files changed, 19 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/carfac/carfac.cc Tue Jun 11 21:32:50 2013 +0000 +++ b/carfac/carfac.cc Tue Jun 11 21:41:53 2013 +0000 @@ -36,6 +36,12 @@ 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, const AGCParams& agc_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()) /
--- a/carfac/carfac.h Tue Jun 11 21:32:50 2013 +0000 +++ b/carfac/carfac.h Tue Jun 11 21:41:53 2013 +0000 @@ -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,
--- a/carfac/carfac_output.cc Tue Jun 11 21:32:50 2013 +0000 +++ b/carfac/carfac_output.cc Tue Jun 11 21:41:53 2013 +0000 @@ -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()); } }
--- a/carfac/carfac_test.cc Tue Jun 11 21:32:50 2013 +0000 +++ b/carfac/carfac_test.cc Tue Jun 11 21:41:53 2013 +0000 @@ -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()) {
--- a/carfac/ear.cc Tue Jun 11 21:32:50 2013 +0000 +++ b/carfac/ear.cc Tue Jun 11 21:41:53 2013 +0000 @@ -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):