[aimc] r299 committed - Update interface to have separate Reset() and Redesign(params) methods...

1 view
Skip to first unread message

ai...@googlecode.com

unread,
Jun 12, 2013, 3:24:53 PM6/12/13
to aimc...@googlegroups.com
Revision: 299
Author: ro...@google.com
Date: Wed Jun 12 12:24:29 2013
Log: Update interface to have separate Reset() and Redesign(params)
methods.


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

Modified:
/trunk/carfac/carfac.cc
/trunk/carfac/carfac.h
/trunk/carfac/ear.cc
/trunk/carfac/ear.h
/trunk/carfac/sai.cc
/trunk/carfac/sai.h

=======================================
--- /trunk/carfac/carfac.cc Tue Jun 11 14:41:53 2013
+++ /trunk/carfac/carfac.cc Wed Jun 12 12:24:29 2013
@@ -33,7 +33,7 @@
CARFAC::CARFAC(const int num_ears, const FPType sample_rate,
const CARParams& car_params, const IHCParams& ihc_params,
const AGCParams& agc_params) {
- Reset(num_ears, sample_rate, car_params, ihc_params, agc_params);
+ Redesign(num_ears, sample_rate, car_params, ihc_params, agc_params);
}

CARFAC::~CARFAC() {
@@ -42,9 +42,9 @@
}
}

-void CARFAC::Reset(const int num_ears, const FPType sample_rate,
- const CARParams& car_params, const IHCParams&
ihc_params,
- const AGCParams& agc_params) {
+void CARFAC::Redesign(const int num_ears, const FPType sample_rate,
+ const CARParams& car_params, const IHCParams&
ihc_params,
+ const AGCParams& agc_params) {
num_ears_ = num_ears;
sample_rate_ = sample_rate;
car_params_ = car_params;
@@ -55,14 +55,14 @@
while (pole_hz > car_params_.min_pole_hz) {
++num_channels_;
pole_hz = pole_hz - car_params_.erb_per_step *
- ERBHz(pole_hz, car_params_.erb_break_freq, car_params_.erb_q);
+ ERBHz(pole_hz, car_params_.erb_break_freq, car_params_.erb_q);
}
pole_freqs_.resize(num_channels_);
pole_hz = car_params_.first_pole_theta * sample_rate_ / (2 * kPi);
for (int channel = 0; channel < num_channels_; ++channel) {
pole_freqs_(channel) = pole_hz;
pole_hz = pole_hz - car_params_.erb_per_step *
- ERBHz(pole_hz, car_params_.erb_break_freq, car_params_.erb_q);
+ ERBHz(pole_hz, car_params_.erb_break_freq, car_params_.erb_q);
}
max_channels_per_octave_ = log(2) / log(pole_freqs_(0) / pole_freqs_(1));
CARCoeffs car_coeffs;
@@ -75,14 +75,20 @@
ears_.reserve(num_ears_);
for (int i = 0; i < num_ears_; ++i) {
if (ears_.size() > i && ears_[i] != NULL) {
- // Reset any existing ears.
- ears_[i]->Reset(num_channels_, car_coeffs, ihc_coeffs, agc_coeffs);
+ // Reinitialize any existing ears.
+ ears_[i]->Redesign(num_channels_, car_coeffs, ihc_coeffs,
agc_coeffs);
} else {
ears_.push_back(
new Ear(num_channels_, car_coeffs, ihc_coeffs, agc_coeffs));
}
}
}
+
+void CARFAC::Reset() {
+ for (Ear* ear : ears_) {
+ ear->Reset();
+ }
+}

void CARFAC::RunSegment(const vector<vector<float>>& sound_data,
const int32_t start, const int32_t length,
=======================================
--- /trunk/carfac/carfac.h Tue Jun 11 14:41:53 2013
+++ /trunk/carfac/carfac.h Wed Jun 12 12:24:29 2013
@@ -49,9 +49,14 @@
const AGCParams& agc_params);
~CARFAC();

- void Reset(const int num_ears, const FPType sample_rate,
- const CARParams& car_params, const IHCParams& ihc_params,
- const AGCParams& agc_params);
+ // Reinitialize using the specified parameters.
+ void Redesign(const int num_ears, const FPType sample_rate,
+ const CARParams& car_params, const IHCParams& ihc_params,
+ const AGCParams& agc_params);
+
+ // Reset the internal state so that subsequent calls to RunSegment are
+ // independent of previous calls. Does not modify the filterbank design.
+ void Reset();

// Processes an individual sound segment and copies the model output to
// seg_output.
=======================================
--- /trunk/carfac/ear.cc Tue Jun 11 14:41:53 2013
+++ /trunk/carfac/ear.cc Wed Jun 12 12:24:29 2013
@@ -29,22 +29,26 @@
Ear::Ear(const int num_channels, const CARCoeffs& car_coeffs,
const IHCCoeffs& ihc_coeffs,
const std::vector<AGCCoeffs>& agc_coeffs) {
- Reset(num_channels, car_coeffs, ihc_coeffs, agc_coeffs);
+ Redesign(num_channels, car_coeffs, ihc_coeffs, agc_coeffs);
}

-void Ear::Reset(const int num_channels, const CARCoeffs& car_coeffs,
- const IHCCoeffs& ihc_coeffs,
- const std::vector<AGCCoeffs>& agc_coeffs) {
+void Ear::Redesign(const int num_channels, const CARCoeffs& car_coeffs,
+ const IHCCoeffs& ihc_coeffs,
+ const std::vector<AGCCoeffs>& agc_coeffs) {
num_channels_ = num_channels;
car_coeffs_ = car_coeffs;
ihc_coeffs_ = ihc_coeffs;
agc_coeffs_ = agc_coeffs;
- ResetCARState();
- ResetIHCState();
- ResetAGCState();
+ Reset();
}

-void Ear::ResetCARState() {
+void Ear::Reset() {
+ InitCARState();
+ InitIHCState();
+ InitAGCState();
+}
+
+void Ear::InitCARState() {
car_state_.z1_memory.setZero(num_channels_);
car_state_.z2_memory.setZero(num_channels_);
car_state_.za_memory.setZero(num_channels_);
@@ -55,7 +59,7 @@
car_state_.dg_memory.setZero(num_channels_);
}

-void Ear::ResetIHCState() {
+void Ear::InitIHCState() {
ihc_state_.ihc_accum = ArrayX::Zero(num_channels_);
if (!ihc_coeffs_.just_half_wave_rectify) {
ihc_state_.ac_coupler.setZero(num_channels_);
@@ -70,7 +74,7 @@
}
}

-void Ear::ResetAGCState() {
+void Ear::InitAGCState() {
int n_agc_stages = agc_coeffs_.size();
agc_state_.resize(n_agc_stages);
for (AGCState& stage_state : agc_state_) {
=======================================
--- /trunk/carfac/ear.h Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/ear.h Wed Jun 12 12:24:29 2013
@@ -39,9 +39,13 @@
const IHCCoeffs& ihc_coeffs,
const std::vector<AGCCoeffs>& agc_coeffs);

- void Reset(const int num_channels, const CARCoeffs& car_coeffs,
- const IHCCoeffs& ihc_coeffs,
- const std::vector<AGCCoeffs>& agc_coeffs);
+ // Reinitialize using the specified parameters.
+ void Redesign(const int num_channels, const CARCoeffs& car_coeffs,
+ const IHCCoeffs& ihc_coeffs,
+ const std::vector<AGCCoeffs>& agc_coeffs);
+
+ // Reset the internal state.
+ void Reset();

// These three methods apply the different steps of the model in sequence
// to individual audio samples during the call to CARFAC::RunSegment.
@@ -102,9 +106,9 @@

private:
// Initializes the model state variables prior to runtime.
- void ResetIHCState();
- void ResetAGCState();
- void ResetCARState();
+ void InitIHCState();
+ void InitAGCState();
+ void InitCARState();

// Helper sub-functions called during the model runtime.
void OHCNonlinearFunction(const ArrayX& velocities,
=======================================
--- /trunk/carfac/sai.cc Tue Jun 11 14:32:50 2013
+++ /trunk/carfac/sai.cc Wed Jun 12 12:24:29 2013
@@ -22,6 +22,10 @@
#include <assert.h>

SAI::SAI(const SAIParams& params) : params_(params) {
+ Redesign(params);
+}
+
+void SAI::Redesign(const SAIParams& params) {
assert(params_.window_width > params_.width &&
"SAI window_width must be larger than width.");

@@ -34,6 +38,11 @@
window_.setLinSpaced(params_.window_width, kPi / params_.window_width,
kPi)
.sin();
}
+
+void SAI::Reset() {
+ input_buffer_.setZero();
+ output_buffer_.setZero();
+}

void SAI::RunSegment(const std::vector<ArrayX>& input,
ArrayXX* output_frame) {
=======================================
--- /trunk/carfac/sai.h Tue Jun 11 15:05:10 2013
+++ /trunk/carfac/sai.h Wed Jun 12 12:24:29 2013
@@ -51,6 +51,12 @@
public:
explicit SAI(const SAIParams& params);

+ // Reinitialize using the specified parameters.
+ void Redesign(const SAIParams& params);
+
+ // Reset the internal state.
+ void Reset();
+
// Fills output_frame with a params_.n_ch by params_.width SAI frame
// computed from the given input frames.
//
Reply all
Reply to author
Forward
0 new messages