annotate trunk/carfac/ear.cc @ 670:443b522fb593

Remove dependency on google logging library in favor of simple asserts.
author ronw@google.com
date Thu, 23 May 2013 16:56:38 +0000
parents 933cf18d9a59
children 7f424c1a8b78
rev   line source
alexbrandmeyer@620 1 //
alexbrandmeyer@620 2 // ear.cc
alexbrandmeyer@620 3 // CARFAC Open Source C++ Library
alexbrandmeyer@620 4 //
alexbrandmeyer@620 5 // Created by Alex Brandmeyer on 5/10/13.
alexbrandmeyer@620 6 //
alexbrandmeyer@620 7 // This C++ file is part of an implementation of Lyon's cochlear model:
alexbrandmeyer@620 8 // "Cascade of Asymmetric Resonators with Fast-Acting Compression"
alexbrandmeyer@620 9 // to supplement Lyon's upcoming book "Human and Machine Hearing"
alexbrandmeyer@620 10 //
alexbrandmeyer@620 11 // Licensed under the Apache License, Version 2.0 (the "License");
alexbrandmeyer@620 12 // you may not use this file except in compliance with the License.
alexbrandmeyer@620 13 // You may obtain a copy of the License at
alexbrandmeyer@620 14 //
alexbrandmeyer@620 15 // http://www.apache.org/licenses/LICENSE-2.0
alexbrandmeyer@620 16 //
alexbrandmeyer@620 17 // Unless required by applicable law or agreed to in writing, software
alexbrandmeyer@620 18 // distributed under the License is distributed on an "AS IS" BASIS,
alexbrandmeyer@620 19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
alexbrandmeyer@620 20 // See the License for the specific language governing permissions and
alexbrandmeyer@620 21 // limitations under the License.
alexbrandmeyer@620 22
ronw@670 23 #include <assert.h>
ronw@670 24
alexbrandmeyer@620 25 #include "ear.h"
alexbrandmeyer@620 26
alexbrandmeyer@621 27 // The 'InitEar' function takes a set of model parameters and initializes the
alexbrandmeyer@621 28 // design coefficients and model state variables needed for running the model
alexbrandmeyer@668 29 // on a single audio channel.
alexbrandmeyer@668 30 void Ear::InitEar(const int n_ch, const FPType fs,
alexbrandmeyer@668 31 const FloatArray& pole_freqs, const CARParams& car_params,
alexbrandmeyer@668 32 const IHCParams& ihc_params, const AGCParams& agc_params) {
alexbrandmeyer@621 33 // The first section of code determines the number of channels that will be
alexbrandmeyer@621 34 // used in the model on the basis of the sample rate and the CAR parameters
alexbrandmeyer@621 35 // that have been passed to this function.
alexbrandmeyer@621 36 n_ch_ = n_ch;
alexbrandmeyer@621 37 // These functions use the parameters that have been passed to design the
alexbrandmeyer@668 38 // coefficients for the first two stages of the model.
alexbrandmeyer@668 39 car_coeffs_.Design(car_params, fs, pole_freqs);
alexbrandmeyer@668 40 ihc_coeffs_.Design(ihc_params, fs);
alexbrandmeyer@668 41 // This code initializes the coefficients for each of the AGC stages.
alexbrandmeyer@668 42 agc_coeffs_.resize(agc_params.n_stages_);
alexbrandmeyer@668 43 FPType previous_stage_gain = 0.0;
alexbrandmeyer@668 44 FPType decim = 1.0;
alexbrandmeyer@668 45 for (int stage = 0; stage < agc_params.n_stages_; ++stage) {
alexbrandmeyer@668 46 agc_coeffs_[stage].Design(agc_params, stage, fs, previous_stage_gain,
alexbrandmeyer@668 47 decim);
alexbrandmeyer@668 48 // Two variables store the decimation and gain levels for use in the design
alexbrandmeyer@668 49 // of the subsequent stages.
alexbrandmeyer@668 50 previous_stage_gain = agc_coeffs_[stage].agc_gain_;
alexbrandmeyer@668 51 decim = agc_coeffs_[stage].decim_;
alexbrandmeyer@668 52 }
alexbrandmeyer@621 53 // Once the coefficients have been determined, we can initialize the state
alexbrandmeyer@621 54 // variables that will be used during runtime.
alexbrandmeyer@621 55 InitCARState();
alexbrandmeyer@621 56 InitIHCState();
alexbrandmeyer@621 57 InitAGCState();
alexbrandmeyer@620 58 }
alexbrandmeyer@620 59
alexbrandmeyer@621 60 void Ear::InitCARState() {
alexbrandmeyer@621 61 car_state_.z1_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 62 car_state_.z2_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 63 car_state_.za_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 64 car_state_.zb_memory_ = car_coeffs_.zr_coeffs_;
alexbrandmeyer@621 65 car_state_.dzb_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 66 car_state_.zy_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 67 car_state_.g_memory_ = car_coeffs_.g0_coeffs_;
alexbrandmeyer@621 68 car_state_.dg_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 69 }
alexbrandmeyer@621 70
alexbrandmeyer@621 71 void Ear::InitIHCState() {
alexbrandmeyer@621 72 ihc_state_.ihc_accum_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 73 if (! ihc_coeffs_.just_hwr_) {
alexbrandmeyer@621 74 ihc_state_.ac_coupler_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 75 ihc_state_.lpf1_state_ = ihc_coeffs_.rest_output_ * FloatArray::Ones(n_ch_);
alexbrandmeyer@621 76 ihc_state_.lpf2_state_ = ihc_coeffs_.rest_output_ * FloatArray::Ones(n_ch_);
alexbrandmeyer@621 77 if (ihc_coeffs_.one_cap_) {
alexbrandmeyer@621 78 ihc_state_.cap1_voltage_ = ihc_coeffs_.rest_cap1_ *
alexbrandmeyer@668 79 FloatArray::Ones(n_ch_);
alexbrandmeyer@621 80 } else {
alexbrandmeyer@621 81 ihc_state_.cap1_voltage_ = ihc_coeffs_.rest_cap1_ *
alexbrandmeyer@668 82 FloatArray::Ones(n_ch_);
alexbrandmeyer@621 83 ihc_state_.cap2_voltage_ = ihc_coeffs_.rest_cap2_ *
alexbrandmeyer@668 84 FloatArray::Ones(n_ch_);
alexbrandmeyer@621 85 }
alexbrandmeyer@621 86 }
alexbrandmeyer@621 87 }
alexbrandmeyer@621 88
alexbrandmeyer@621 89 void Ear::InitAGCState() {
alexbrandmeyer@668 90 int n_agc_stages = agc_coeffs_.size();
alexbrandmeyer@668 91 agc_state_.resize(n_agc_stages);
alexbrandmeyer@668 92 for (int i = 0; i < n_agc_stages; ++i) {
alexbrandmeyer@668 93 agc_state_[i].decim_phase_ = 0;
alexbrandmeyer@668 94 agc_state_[i].agc_memory_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@668 95 agc_state_[i].input_accum_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@621 96 }
alexbrandmeyer@621 97 }
alexbrandmeyer@621 98
alexbrandmeyer@668 99 void Ear::CARStep(const FPType input, FloatArray* car_out) {
alexbrandmeyer@668 100 // This interpolates g.
alexbrandmeyer@668 101 car_state_.g_memory_ = car_state_.g_memory_ + car_state_.dg_memory_;
alexbrandmeyer@621 102 // This calculates the AGC interpolation state.
alexbrandmeyer@668 103 car_state_.zb_memory_ = car_state_.zb_memory_ + car_state_.dzb_memory_;
alexbrandmeyer@621 104 // This updates the nonlinear function of 'velocity' along with zA, which is
alexbrandmeyer@621 105 // a delay of z2.
alexbrandmeyer@668 106 FloatArray nonlinear_fun(n_ch_);
alexbrandmeyer@668 107 FloatArray velocities = car_state_.z2_memory_ - car_state_.za_memory_;
alexbrandmeyer@668 108 OHCNonlinearFunction(velocities, &nonlinear_fun);
alexbrandmeyer@668 109 // Here, zb_memory_ * nonlinear_fun is "undamping" delta r.
alexbrandmeyer@668 110 FloatArray r = car_coeffs_.r1_coeffs_ + (car_state_.zb_memory_ *
alexbrandmeyer@668 111 nonlinear_fun);
alexbrandmeyer@668 112 car_state_.za_memory_ = car_state_.z2_memory_;
alexbrandmeyer@621 113 // Here we reduce the CAR state by r and rotate with the fixed cos/sin coeffs.
alexbrandmeyer@668 114 FloatArray z1 = r * ((car_coeffs_.a0_coeffs_ * car_state_.z1_memory_) -
alexbrandmeyer@668 115 (car_coeffs_.c0_coeffs_ * car_state_.z2_memory_));
alexbrandmeyer@668 116 car_state_.z2_memory_ = r *
alexbrandmeyer@668 117 ((car_coeffs_.c0_coeffs_ * car_state_.z1_memory_) +
alexbrandmeyer@668 118 (car_coeffs_.a0_coeffs_ * car_state_.z2_memory_));
alexbrandmeyer@668 119 car_state_.zy_memory_ = car_coeffs_.h_coeffs_ * car_state_.z2_memory_;
alexbrandmeyer@621 120 // This section ripples the input-output path, to avoid delay...
alexbrandmeyer@621 121 // It's the only part that doesn't get computed "in parallel":
alexbrandmeyer@668 122 FPType in_out = input;
alexbrandmeyer@621 123 for (int ch = 0; ch < n_ch_; ch++) {
alexbrandmeyer@620 124 z1(ch) = z1(ch) + in_out;
alexbrandmeyer@621 125 // This performs the ripple, and saves the final channel outputs in zy.
alexbrandmeyer@668 126 in_out = car_state_.g_memory_(ch) * (in_out + car_state_.zy_memory_(ch));
alexbrandmeyer@668 127 car_state_.zy_memory_(ch) = in_out;
alexbrandmeyer@620 128 }
alexbrandmeyer@620 129 car_state_.z1_memory_ = z1;
alexbrandmeyer@668 130 *car_out = car_state_.zy_memory_;
alexbrandmeyer@620 131 }
alexbrandmeyer@620 132
alexbrandmeyer@621 133 // We start with a quadratic nonlinear function, and limit it via a
alexbrandmeyer@621 134 // rational function. This makes the result go to zero at high
alexbrandmeyer@620 135 // absolute velocities, so it will do nothing there.
alexbrandmeyer@668 136 void Ear::OHCNonlinearFunction(const FloatArray& velocities,
alexbrandmeyer@668 137 FloatArray* nonlinear_fun) {
alexbrandmeyer@668 138 *nonlinear_fun = (1 + ((velocities * car_coeffs_.velocity_scale_) +
alexbrandmeyer@668 139 car_coeffs_.v_offset_).square()).inverse();
alexbrandmeyer@620 140 }
alexbrandmeyer@620 141
alexbrandmeyer@621 142 // This step is a one sample-time update of the inner-hair-cell (IHC) model,
alexbrandmeyer@621 143 // including the detection nonlinearity and either one or two capacitor state
alexbrandmeyer@621 144 // variables.
alexbrandmeyer@668 145 void Ear::IHCStep(const FloatArray& car_out, FloatArray* ihc_out) {
alexbrandmeyer@668 146 FloatArray ac_diff = car_out - ihc_state_.ac_coupler_;
alexbrandmeyer@620 147 ihc_state_.ac_coupler_ = ihc_state_.ac_coupler_ +
alexbrandmeyer@668 148 (ihc_coeffs_.ac_coeff_ * ac_diff);
alexbrandmeyer@620 149 if (ihc_coeffs_.just_hwr_) {
alexbrandmeyer@668 150 FloatArray output(n_ch_);
alexbrandmeyer@668 151 for (int ch = 0; ch < n_ch_; ++ch) {
alexbrandmeyer@668 152 FPType a = (ac_diff(ch) > 0.0) ? ac_diff(ch) : 0.0;
alexbrandmeyer@668 153 output(ch) = (a < 2) ? a : 2;
alexbrandmeyer@620 154 }
alexbrandmeyer@668 155 *ihc_out = output;
alexbrandmeyer@620 156 } else {
alexbrandmeyer@668 157 FloatArray conductance = CARFACDetect(ac_diff);
alexbrandmeyer@620 158 if (ihc_coeffs_.one_cap_) {
alexbrandmeyer@668 159 *ihc_out = conductance * ihc_state_.cap1_voltage_;
alexbrandmeyer@620 160 ihc_state_.cap1_voltage_ = ihc_state_.cap1_voltage_ -
alexbrandmeyer@668 161 (*ihc_out * ihc_coeffs_.out1_rate_) +
alexbrandmeyer@668 162 ((1 - ihc_state_.cap1_voltage_)
alexbrandmeyer@668 163 * ihc_coeffs_.in1_rate_);
alexbrandmeyer@620 164 } else {
alexbrandmeyer@668 165 *ihc_out = conductance * ihc_state_.cap2_voltage_;
alexbrandmeyer@620 166 ihc_state_.cap1_voltage_ = ihc_state_.cap1_voltage_ -
alexbrandmeyer@668 167 ((ihc_state_.cap1_voltage_ - ihc_state_.cap2_voltage_)
alexbrandmeyer@668 168 * ihc_coeffs_.out1_rate_) +
alexbrandmeyer@668 169 ((1 - ihc_state_.cap1_voltage_) * ihc_coeffs_.in1_rate_);
alexbrandmeyer@620 170 ihc_state_.cap2_voltage_ = ihc_state_.cap2_voltage_ -
alexbrandmeyer@668 171 (*ihc_out * ihc_coeffs_.out2_rate_) +
alexbrandmeyer@668 172 ((ihc_state_.cap1_voltage_ - ihc_state_.cap2_voltage_)
alexbrandmeyer@668 173 * ihc_coeffs_.in2_rate_);
alexbrandmeyer@620 174 }
alexbrandmeyer@621 175 // Here we smooth the output twice using a LPF.
alexbrandmeyer@668 176 *ihc_out *= ihc_coeffs_.output_gain_;
alexbrandmeyer@620 177 ihc_state_.lpf1_state_ = ihc_state_.lpf1_state_ +
alexbrandmeyer@668 178 (ihc_coeffs_.lpf_coeff_ *
alexbrandmeyer@668 179 (*ihc_out - ihc_state_.lpf1_state_));
alexbrandmeyer@620 180 ihc_state_.lpf2_state_ = ihc_state_.lpf2_state_ +
alexbrandmeyer@668 181 (ihc_coeffs_.lpf_coeff_ *
alexbrandmeyer@668 182 (ihc_state_.lpf1_state_ - ihc_state_.lpf2_state_));
alexbrandmeyer@668 183 *ihc_out = ihc_state_.lpf2_state_ - ihc_coeffs_.rest_output_;
alexbrandmeyer@620 184 }
alexbrandmeyer@668 185 ihc_state_.ihc_accum_ += *ihc_out;
alexbrandmeyer@620 186 }
alexbrandmeyer@620 187
alexbrandmeyer@668 188 bool Ear::AGCStep(const FloatArray& ihc_out) {
alexbrandmeyer@620 189 int stage = 0;
alexbrandmeyer@668 190 int n_stages = agc_coeffs_[0].n_agc_stages_;
alexbrandmeyer@668 191 FPType detect_scale = agc_coeffs_[n_stages - 1].detect_scale_;
alexbrandmeyer@668 192 bool updated = AGCRecurse(stage, detect_scale * ihc_out);
alexbrandmeyer@620 193 return updated;
alexbrandmeyer@620 194 }
alexbrandmeyer@620 195
alexbrandmeyer@668 196 bool Ear::AGCRecurse(const int stage, FloatArray agc_in) {
alexbrandmeyer@620 197 bool updated = true;
alexbrandmeyer@621 198 // This is the decim factor for this stage, relative to input or prev. stage:
alexbrandmeyer@668 199 int decim = agc_coeffs_[stage].decimation_;
alexbrandmeyer@621 200 // This is the decim phase of this stage (do work on phase 0 only):
alexbrandmeyer@668 201 int decim_phase = agc_state_[stage].decim_phase_ + 1;
alexbrandmeyer@620 202 decim_phase = decim_phase % decim;
alexbrandmeyer@668 203 agc_state_[stage].decim_phase_ = decim_phase;
alexbrandmeyer@621 204 // Here we accumulate input for this stage from the previous stage:
alexbrandmeyer@668 205 agc_state_[stage].input_accum_ += agc_in;
alexbrandmeyer@621 206 // We don't do anything if it's not the right decim_phase.
alexbrandmeyer@621 207 if (decim_phase == 0) {
alexbrandmeyer@621 208 // Now we do lots of work, at the decimated rate.
alexbrandmeyer@621 209 // These are the decimated inputs for this stage, which will be further
alexbrandmeyer@621 210 // decimated at the next stage.
alexbrandmeyer@668 211 agc_in = agc_state_[stage].input_accum_ / decim;
alexbrandmeyer@621 212 // This resets the accumulator.
alexbrandmeyer@668 213 agc_state_[stage].input_accum_ = FloatArray::Zero(n_ch_);
alexbrandmeyer@668 214 if (stage < (agc_coeffs_.size() - 1)) {
alexbrandmeyer@621 215 // Now we recurse to evaluate the next stage(s).
alexbrandmeyer@668 216 // TODO (alexbrandmeyer): the Matlab version of AGCRecurse can return a
alexbrandmeyer@668 217 // value for updated, but isn't used in that version. Check with Dick to
alexbrandmeyer@668 218 // see if that is needed.
alexbrandmeyer@621 219 updated = AGCRecurse(stage + 1, agc_in);
alexbrandmeyer@621 220 // Afterwards we add its output to this stage input, whether it updated or
alexbrandmeyer@621 221 // not.
alexbrandmeyer@668 222 agc_in += agc_coeffs_[stage].agc_stage_gain_ *
alexbrandmeyer@668 223 agc_state_[stage + 1].agc_memory_;
alexbrandmeyer@620 224 }
alexbrandmeyer@668 225 FloatArray agc_stage_state = agc_state_[stage].agc_memory_;
alexbrandmeyer@621 226 // This performs a first-order recursive smoothing filter update, in time.
alexbrandmeyer@668 227 agc_stage_state += agc_coeffs_[stage].agc_epsilon_ *
alexbrandmeyer@668 228 (agc_in - agc_stage_state);
alexbrandmeyer@620 229 agc_stage_state = AGCSpatialSmooth(stage, agc_stage_state);
alexbrandmeyer@668 230 agc_state_[stage].agc_memory_ = agc_stage_state;
alexbrandmeyer@668 231 updated = true;
alexbrandmeyer@620 232 } else {
alexbrandmeyer@620 233 updated = false;
alexbrandmeyer@620 234 }
alexbrandmeyer@620 235 return updated;
alexbrandmeyer@620 236 }
alexbrandmeyer@620 237
alexbrandmeyer@668 238 // TODO (alexbrandmeyer): figure out how to operate directly on stage_state.
alexbrandmeyer@668 239 // Using a pointer breaks the () indexing of the Eigen arrays, but there must
alexbrandmeyer@668 240 // be a way around this.
alexbrandmeyer@668 241 FloatArray Ear::AGCSpatialSmooth(const int stage, FloatArray stage_state) {
alexbrandmeyer@668 242 int n_iterations = agc_coeffs_[stage].agc_spatial_iterations_;
alexbrandmeyer@620 243 bool use_fir;
alexbrandmeyer@621 244 use_fir = (n_iterations < 4) ? true : false;
alexbrandmeyer@620 245 if (use_fir) {
alexbrandmeyer@668 246 std::vector<FPType> fir_coeffs = agc_coeffs_[stage].agc_spatial_fir_;
alexbrandmeyer@620 247 FloatArray ss_tap1(n_ch_);
alexbrandmeyer@620 248 FloatArray ss_tap2(n_ch_);
alexbrandmeyer@620 249 FloatArray ss_tap3(n_ch_);
alexbrandmeyer@620 250 FloatArray ss_tap4(n_ch_);
alexbrandmeyer@668 251 int n_taps = agc_coeffs_[stage].agc_spatial_n_taps_;
alexbrandmeyer@621 252 // This initializes the first two taps of stage state, which are used for
alexbrandmeyer@621 253 // both possible cases.
alexbrandmeyer@620 254 ss_tap1(0) = stage_state(0);
alexbrandmeyer@621 255 ss_tap1.block(1, 0, n_ch_ - 1, 1) = stage_state.block(0, 0, n_ch_ - 1, 1);
alexbrandmeyer@621 256 ss_tap2(n_ch_ - 1) = stage_state(n_ch_ - 1);
alexbrandmeyer@621 257 ss_tap2.block(0, 0, n_ch_ - 1, 1) = stage_state.block(1, 0, n_ch_ - 1, 1);
alexbrandmeyer@620 258 switch (n_taps) {
alexbrandmeyer@620 259 case 3:
alexbrandmeyer@668 260 stage_state = (fir_coeffs[0] * ss_tap1) +
alexbrandmeyer@668 261 (fir_coeffs[1] * stage_state) +
alexbrandmeyer@668 262 (fir_coeffs[2] * ss_tap2);
alexbrandmeyer@620 263 break;
alexbrandmeyer@620 264 case 5:
alexbrandmeyer@621 265 // Now we initialize last two taps of stage state, which are only used
alexbrandmeyer@621 266 // for the 5-tap case.
alexbrandmeyer@620 267 ss_tap3(0) = stage_state(0);
alexbrandmeyer@620 268 ss_tap3(1) = stage_state(1);
alexbrandmeyer@621 269 ss_tap3.block(2, 0, n_ch_ - 2, 1) =
alexbrandmeyer@668 270 stage_state.block(0, 0, n_ch_ - 2, 1);
alexbrandmeyer@621 271 ss_tap4(n_ch_ - 2) = stage_state(n_ch_ - 1);
alexbrandmeyer@621 272 ss_tap4(n_ch_ - 1) = stage_state(n_ch_ - 2);
alexbrandmeyer@621 273 ss_tap4.block(0, 0, n_ch_ - 2, 1) =
alexbrandmeyer@668 274 stage_state.block(2, 0, n_ch_ - 2, 1);
alexbrandmeyer@668 275 stage_state = (fir_coeffs[0] * (ss_tap3 + ss_tap1)) +
alexbrandmeyer@668 276 (fir_coeffs[1] * stage_state) +
alexbrandmeyer@668 277 (fir_coeffs[2] * (ss_tap2 + ss_tap4));
alexbrandmeyer@620 278 break;
alexbrandmeyer@620 279 default:
ronw@670 280 assert(true && "Bad n_taps in AGCSpatialSmooth; should be 3 or 5.");
alexbrandmeyer@622 281 break;
alexbrandmeyer@620 282 }
alexbrandmeyer@620 283 } else {
alexbrandmeyer@621 284 stage_state = AGCSmoothDoubleExponential(stage_state,
alexbrandmeyer@668 285 agc_coeffs_[stage].agc_pole_z1_,
alexbrandmeyer@668 286 agc_coeffs_[stage].agc_pole_z2_);
alexbrandmeyer@620 287 }
alexbrandmeyer@620 288 return stage_state;
alexbrandmeyer@620 289 }
alexbrandmeyer@620 290
alexbrandmeyer@668 291 // TODO (alexbrandmeyer): figure out how to operate directly on stage_state.
alexbrandmeyer@668 292 // Same point as above for AGCSpatialSmooth.
alexbrandmeyer@621 293 FloatArray Ear::AGCSmoothDoubleExponential(FloatArray stage_state,
alexbrandmeyer@668 294 const FPType pole_z1,
alexbrandmeyer@668 295 const FPType pole_z2) {
alexbrandmeyer@622 296 int32_t n_pts = stage_state.size();
alexbrandmeyer@621 297 FPType input;
alexbrandmeyer@622 298 FPType state = 0.0;
alexbrandmeyer@668 299 // TODO (alexbrandmeyer): I'm assuming one dimensional input for now, but this
alexbrandmeyer@621 300 // should be verified with Dick for the final version
alexbrandmeyer@668 301 for (int i = n_pts - 11; i < n_pts; ++i){
alexbrandmeyer@621 302 input = stage_state(i);
alexbrandmeyer@621 303 state = state + (1 - pole_z1) * (input - state);
alexbrandmeyer@621 304 }
alexbrandmeyer@668 305 for (int i = n_pts - 1; i > -1; --i){
alexbrandmeyer@621 306 input = stage_state(i);
alexbrandmeyer@621 307 state = state + (1 - pole_z2) * (input - state);
alexbrandmeyer@621 308 }
alexbrandmeyer@668 309 for (int i = 0; i < n_pts; ++i){
alexbrandmeyer@621 310 input = stage_state(i);
alexbrandmeyer@621 311 state = state + (1 - pole_z1) * (input - state);
alexbrandmeyer@621 312 stage_state(i) = state;
alexbrandmeyer@621 313 }
alexbrandmeyer@620 314 return stage_state;
alexbrandmeyer@620 315 }
alexbrandmeyer@621 316
alexbrandmeyer@668 317 FloatArray Ear::StageGValue(const FloatArray& undamping) {
alexbrandmeyer@668 318 FloatArray r = car_coeffs_.r1_coeffs_ + car_coeffs_.zr_coeffs_ * undamping;
alexbrandmeyer@668 319 return (1 - 2 * r * car_coeffs_.a0_coeffs_ + (r * r)) /
alexbrandmeyer@668 320 (1 - 2 * r * car_coeffs_.a0_coeffs_ +
alexbrandmeyer@668 321 car_coeffs_.h_coeffs_ * r * car_coeffs_.c0_coeffs_ + (r * r));
ronw@670 322 }