Mercurial > hg > aimc
changeset 682:10dc41e4d2f2
More small style revisions to C++ CARFAC, adjusted struct member variable naming, header guards and #include structure.
author | alexbrandmeyer |
---|---|
date | Wed, 29 May 2013 15:37:28 +0000 |
parents | 7def70bdd6b6 |
children | 66688b9f8853 |
files | trunk/carfac/SConstruct trunk/carfac/agc_coeffs.h trunk/carfac/agc_params.h trunk/carfac/agc_state.h trunk/carfac/car_coeffs.h trunk/carfac/car_params.h trunk/carfac/car_state.h trunk/carfac/carfac.cc trunk/carfac/carfac.h trunk/carfac/carfac_common.h trunk/carfac/carfac_output.h trunk/carfac/carfac_test.cc trunk/carfac/ear.cc trunk/carfac/ear.h trunk/carfac/ihc_coeffs.h trunk/carfac/ihc_params.h trunk/carfac/ihc_state.h |
diffstat | 17 files changed, 380 insertions(+), 365 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/carfac/SConstruct Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/SConstruct Wed May 29 15:37:28 2013 +0000 @@ -64,7 +64,7 @@ if GCC_VERSION.startswith('4.6'): env.MergeFlags(['-std=c++0x']) else: - env.MergeFlags(['-std=c++11x']) + env.MergeFlags(['-std=c++11']) env.Library(target = 'carfac', source = carfac_sources)
--- a/trunk/carfac/agc_coeffs.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/agc_coeffs.h Wed May 29 15:37:28 2013 +0000 @@ -20,27 +20,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_AGCCoeffs_h -#define CARFAC_Open_Source_C__Library_AGCCoeffs_h +#ifndef CARFAC_AGC_COEFFS_H +#define CARFAC_AGC_COEFFS_H -#include "agc_params.h" +#include "carfac_common.h" struct AGCCoeffs { - int n_agc_stages_; - FPType agc_stage_gain_; - FPType agc_epsilon_; - int decimation_; - FPType agc_pole_z1_; - FPType agc_pole_z2_; - int agc_spatial_iterations_; - FPType agc_spatial_fir_left_; - FPType agc_spatial_fir_mid_; - FPType agc_spatial_fir_right_; - int agc_spatial_n_taps_; - FPType agc_mix_coeffs_; - FPType agc_gain_; - FPType detect_scale_; - FPType decim_; + int n_agc_stages; + FPType agc_stage_gain; + FPType agc_epsilon; + int decimation; + FPType agc_pole_z1; + FPType agc_pole_z2; + int agc_spatial_iterations; + FPType agc_spatial_fir_left; + FPType agc_spatial_fir_mid; + FPType agc_spatial_fir_right; + int agc_spatial_n_taps; + FPType agc_mix_coeffs; + FPType agc_gain; + FPType detect_scale; + FPType decim; }; -#endif \ No newline at end of file +#endif // CARFAC_AGC_COEFFS_H \ No newline at end of file
--- a/trunk/carfac/agc_params.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/agc_params.h Wed May 29 15:37:28 2013 +0000 @@ -20,36 +20,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_AGCParams_h -#define CARFAC_Open_Source_C__Library_AGCParams_h +#ifndef CARFAC_AGC_PARAMS_H +#define CARFAC_AGC_PARAMS_H +#include <vector> #include "carfac_common.h" struct AGCParams { AGCParams() { - n_stages_ = 4; - agc_stage_gain_ = 2.0; - time_constants_.resize(n_stages_); - agc1_scales_.resize(n_stages_); - agc2_scales_.resize(n_stages_); - agc1_scales_[0] = 1.0; - agc2_scales_[0] = 1.65; - time_constants_[0] = 0.002; - for (int i = 1; i < n_stages_; ++i) { - agc1_scales_[i] = agc1_scales_[i - 1] * sqrt(2.0); - agc2_scales_[i] = agc2_scales_[i - 1] * sqrt(2.0); - time_constants_[i] = time_constants_[i - 1] * 4.0; + n_stages = 4; + agc_stage_gain = 2.0; + time_constants.resize(n_stages); + agc1_scales.resize(n_stages); + agc2_scales.resize(n_stages); + agc1_scales[0] = 1.0; + agc2_scales[0] = 1.65; + time_constants[0] = 0.002; + for (int i = 1; i < n_stages; ++i) { + agc1_scales[i] = agc1_scales[i - 1] * sqrt(2.0); + agc2_scales[i] = agc2_scales[i - 1] * sqrt(2.0); + time_constants[i] = time_constants[i - 1] * 4.0; } - decimation_ = {8, 2, 2, 2}; - agc_mix_coeff_ = 0.5; + decimation = {8, 2, 2, 2}; + agc_mix_coeff = 0.5; } - int n_stages_; - FPType agc_stage_gain_; - FPType agc_mix_coeff_; - std::vector<FPType> time_constants_; - std::vector<int> decimation_; - std::vector<FPType> agc1_scales_; - std::vector<FPType> agc2_scales_; + int n_stages; + FPType agc_stage_gain; + FPType agc_mix_coeff; + std::vector<FPType> time_constants; + std::vector<int> decimation; + std::vector<FPType> agc1_scales; + std::vector<FPType> agc2_scales; }; -#endif +#endif // CARFAC_AGC_PARAMS_H \ No newline at end of file
--- a/trunk/carfac/agc_state.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/agc_state.h Wed May 29 15:37:28 2013 +0000 @@ -20,16 +20,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_AGCState_h -#define CARFAC_Open_Source_C__Library_AGCState_h +#ifndef CARFAC_AGC_STATE_H +#define CARFAC_AGC_STATE_H -#include "agc_coeffs.h" +#include "carfac_common.h" struct AGCState { - int n_ch_; - FloatArray agc_memory_; - FloatArray input_accum_; - int decim_phase_; + int n_ch; + FloatArray agc_memory; + FloatArray input_accum; + int decim_phase; }; -#endif \ No newline at end of file +#endif // CARFAC_AGC_STATE_H \ No newline at end of file
--- a/trunk/carfac/car_coeffs.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/car_coeffs.h Wed May 29 15:37:28 2013 +0000 @@ -20,21 +20,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_CARCoeffs_h -#define CARFAC_Open_Source_C__Library_CARCoeffs_h +#ifndef CARFAC_CAR_COEFFS_H +#define CARFAC_CAR_COEFFS_H -#include "car_params.h" +#include "carfac_common.h" struct CARCoeffs { - int n_ch_; - FPType velocity_scale_; - FPType v_offset_; - FloatArray r1_coeffs_; - FloatArray a0_coeffs_; - FloatArray c0_coeffs_; - FloatArray h_coeffs_; - FloatArray g0_coeffs_; - FloatArray zr_coeffs_; + int n_ch; + FPType velocity_scale; + FPType v_offset; + FloatArray r1_coeffs; + FloatArray a0_coeffs; + FloatArray c0_coeffs; + FloatArray h_coeffs; + FloatArray g0_coeffs; + FloatArray zr_coeffs; }; -#endif \ No newline at end of file +#endif // CARFAC_CAR_COEFFS_H \ No newline at end of file
--- a/trunk/carfac/car_params.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/car_params.h Wed May 29 15:37:28 2013 +0000 @@ -20,38 +20,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_CARParams_h -#define CARFAC_Open_Source_C__Library_CARParams_h +#ifndef CARFAC_CAR_PARAMS_H +#define CARFAC_CAR_PARAMS_H #include "carfac_common.h" struct CARParams { // The constructor initializes using default parameter values. CARParams() { - velocity_scale_ = 0.1; - v_offset_ = 0.04; - min_zeta_ = 0.1; - max_zeta_ = 0.35; - first_pole_theta_ = 0.85 * kPi; - zero_ratio_ = sqrt(2.0); - high_f_damping_compression_ = 0.5; - erb_per_step_ = 0.5; - min_pole_hz_ = 30; - erb_break_freq_ = 165.3; // This is the Greenwood map's break frequency. + velocity_scale = 0.1; + v_offset = 0.04; + min_zeta = 0.1; + max_zeta = 0.35; + first_pole_theta = 0.85 * kPi; + zero_ratio = sqrt(2.0); + high_f_damping_compression = 0.5; + erb_per_step = 0.5; + min_pole_hz = 30; + erb_break_freq = 165.3; // This is the Greenwood map's break frequency. // This represents Glassberg and Moore's high-cf ratio. - erb_q_ = 1000/(24.7*4.37); + erb_q = 1000/(24.7*4.37); }; - FPType velocity_scale_; // This is used for the velocity nonlinearity. - FPType v_offset_; // The offset gives us quadratic part. - FPType min_zeta_; // This is the minimum damping factor in mid-freq channels. - FPType max_zeta_; // This is the maximum damping factor in mid-freq channels. - FPType first_pole_theta_; - FPType zero_ratio_; // This is how far zero is above the pole. - FPType high_f_damping_compression_; // A range from 0 to 1 to compress theta. - FPType erb_per_step_; - FPType min_pole_hz_; - FPType erb_break_freq_; - FPType erb_q_; + FPType velocity_scale; // This is used for the velocity nonlinearity. + FPType v_offset; // The offset gives us quadratic part. + FPType min_zeta; // This is the minimum damping factor in mid-freq channels. + FPType max_zeta; // This is the maximum damping factor in mid-freq channels. + FPType first_pole_theta; + FPType zero_ratio; // This is how far zero is above the pole. + FPType high_f_damping_compression; // A range from 0 to 1 to compress theta. + FPType erb_per_step; + FPType min_pole_hz; + FPType erb_break_freq; + FPType erb_q; }; -#endif \ No newline at end of file +#endif // CARFAC_CAR_PARAMS_H \ No newline at end of file
--- a/trunk/carfac/car_state.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/car_state.h Wed May 29 15:37:28 2013 +0000 @@ -20,20 +20,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_CARState_h -#define CARFAC_Open_Source_C__Library_CARState_h +#ifndef CARFAC_CAR_STATE_H +#define CARFAC_CAR_STATE_H -#include "car_coeffs.h" +#include "carfac_common.h" struct CARState { - FloatArray z1_memory_; - FloatArray z2_memory_; - FloatArray za_memory_; - FloatArray zb_memory_; - FloatArray dzb_memory_; - FloatArray zy_memory_; - FloatArray g_memory_; - FloatArray dg_memory_; + FloatArray z1_memory; + FloatArray z2_memory; + FloatArray za_memory; + FloatArray zb_memory; + FloatArray dzb_memory; + FloatArray zy_memory; + FloatArray g_memory; + FloatArray dg_memory; }; -#endif \ No newline at end of file +#endif // CARFAC_CAR_STATE_H \ No newline at end of file
--- a/trunk/carfac/carfac.cc Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/carfac.cc Wed May 29 15:37:28 2013 +0000 @@ -19,6 +19,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + #include <assert.h> #include "carfac.h" using std::vector; @@ -30,18 +31,18 @@ fs_ = fs; ears_.resize(n_ears_); n_ch_ = 0; - FPType pole_hz = car_params.first_pole_theta_ * fs / (2 * kPi); - while (pole_hz > car_params.min_pole_hz_) { + FPType pole_hz = car_params.first_pole_theta * fs / (2 * kPi); + while (pole_hz > car_params.min_pole_hz) { ++n_ch_; - pole_hz = pole_hz - car_params.erb_per_step_ * - ERBHz(pole_hz, car_params.erb_break_freq_, car_params.erb_q_); + pole_hz = pole_hz - car_params.erb_per_step * + ERBHz(pole_hz, car_params.erb_break_freq, car_params.erb_q); } pole_freqs_.resize(n_ch_); - pole_hz = car_params.first_pole_theta_ * fs / (2 * kPi); + pole_hz = car_params.first_pole_theta * fs / (2 * kPi); for (int ch = 0; ch < n_ch_; ++ch) { pole_freqs_(ch) = pole_hz; - pole_hz = pole_hz - car_params.erb_per_step_ * - ERBHz(pole_hz, car_params.erb_break_freq_, car_params.erb_q_); + pole_hz = pole_hz - car_params.erb_per_step * + 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; @@ -151,44 +152,44 @@ const FloatArray& pole_freqs, CARCoeffs* car_coeffs) { n_ch_ = pole_freqs.size(); - car_coeffs->velocity_scale_ = car_params.velocity_scale_; - car_coeffs->v_offset_ = car_params.v_offset_; - car_coeffs->r1_coeffs_.resize(n_ch_); - car_coeffs->a0_coeffs_.resize(n_ch_); - car_coeffs->c0_coeffs_.resize(n_ch_); - car_coeffs->h_coeffs_.resize(n_ch_); - car_coeffs->g0_coeffs_.resize(n_ch_); - FPType f = car_params.zero_ratio_ * car_params.zero_ratio_ - 1.0; + car_coeffs->velocity_scale = car_params.velocity_scale; + car_coeffs->v_offset = car_params.v_offset; + car_coeffs->r1_coeffs.resize(n_ch_); + car_coeffs->a0_coeffs.resize(n_ch_); + car_coeffs->c0_coeffs.resize(n_ch_); + car_coeffs->h_coeffs.resize(n_ch_); + car_coeffs->g0_coeffs.resize(n_ch_); + FPType f = car_params.zero_ratio * car_params.zero_ratio - 1.0; FloatArray theta = pole_freqs * ((2.0 * kPi) / fs); - car_coeffs->c0_coeffs_ = theta.sin(); - car_coeffs->a0_coeffs_ = theta.cos(); - FPType ff = car_params.high_f_damping_compression_; + car_coeffs->c0_coeffs = theta.sin(); + car_coeffs->a0_coeffs = theta.cos(); + FPType ff = car_params.high_f_damping_compression; FloatArray x = theta / kPi; - car_coeffs->zr_coeffs_ = kPi * (x - (ff * (x*x*x))); - FPType max_zeta = car_params.max_zeta_; - FPType min_zeta = car_params.min_zeta_; - car_coeffs->r1_coeffs_ = (1.0 - (car_coeffs->zr_coeffs_ * max_zeta)); + car_coeffs->zr_coeffs = kPi * (x - (ff * (x*x*x))); + FPType max_zeta = car_params.max_zeta; + FPType min_zeta = car_params.min_zeta; + car_coeffs->r1_coeffs = (1.0 - (car_coeffs->zr_coeffs * max_zeta)); FloatArray erb_freqs(n_ch_); for (int ch=0; ch < n_ch_; ++ch) { - erb_freqs(ch) = ERBHz(pole_freqs(ch), car_params.erb_break_freq_, - car_params.erb_q_); + erb_freqs(ch) = ERBHz(pole_freqs(ch), car_params.erb_break_freq, + car_params.erb_q); } FloatArray min_zetas = min_zeta + (0.25 * ((erb_freqs / pole_freqs) - min_zeta)); - car_coeffs->zr_coeffs_ *= max_zeta - min_zetas; - car_coeffs->h_coeffs_ = car_coeffs->c0_coeffs_ * f; + car_coeffs->zr_coeffs *= max_zeta - min_zetas; + car_coeffs->h_coeffs = car_coeffs->c0_coeffs * f; FloatArray relative_undamping = FloatArray::Ones(n_ch_); - FloatArray r = car_coeffs->r1_coeffs_ + (car_coeffs->zr_coeffs_ * + FloatArray r = car_coeffs->r1_coeffs + (car_coeffs->zr_coeffs * relative_undamping); - car_coeffs->g0_coeffs_ = (1.0 - (2.0 * r * car_coeffs->a0_coeffs_) + (r*r)) / - (1 - (2 * r * car_coeffs->a0_coeffs_) + - (car_coeffs->h_coeffs_ * r * car_coeffs->c0_coeffs_) + (r*r)); + car_coeffs->g0_coeffs = (1.0 - (2.0 * r * car_coeffs->a0_coeffs) + (r*r)) / + (1 - (2 * r * car_coeffs->a0_coeffs) + + (car_coeffs->h_coeffs * r * car_coeffs->c0_coeffs) + (r*r)); } void CARFAC::DesignIHCCoeffs(const IHCParams& ihc_params, const FPType fs, IHCCoeffs* ihc_coeffs) { - if (ihc_params.just_half_wave_rectify_) { - ihc_coeffs->just_half_wave_rectify_ = ihc_params.just_half_wave_rectify_; + if (ihc_params.just_half_wave_rectify) { + ihc_coeffs->just_half_wave_rectify = ihc_params.just_half_wave_rectify; } else { // This section calculates conductance values using two pre-defined scalars. FloatArray x(1); @@ -199,78 +200,78 @@ x(0) = 0.0; x = CARFACDetect(x); conduct_at_0 = x(0); - if (ihc_params.one_capacitor_) { + if (ihc_params.one_capacitor) { FPType ro = 1 / conduct_at_10 ; - FPType c = ihc_params.tau1_out_ / ro; - FPType ri = ihc_params.tau1_in_ / c; + FPType c = ihc_params.tau1_out / ro; + FPType ri = ihc_params.tau1_in / c; FPType saturation_output = 1 / ((2 * ro) + ri); FPType r0 = 1 / conduct_at_0; FPType current = 1 / (ri + r0); - ihc_coeffs->cap1_voltage_ = 1 - (current * ri); - ihc_coeffs->just_half_wave_rectify_ = false; - ihc_coeffs->lpf_coeff_ = 1 - exp( -1 / (ihc_params.tau_lpf_ * fs)); - ihc_coeffs->out1_rate_ = ro / (ihc_params.tau1_out_ * fs); - ihc_coeffs->in1_rate_ = 1 / (ihc_params.tau1_in_ * fs); - ihc_coeffs->one_capacitor_ = ihc_params.one_capacitor_; - ihc_coeffs->output_gain_ = 1 / (saturation_output - current); - ihc_coeffs->rest_output_ = current / (saturation_output - current); - ihc_coeffs->rest_cap1_ = ihc_coeffs->cap1_voltage_; + ihc_coeffs->cap1_voltage = 1 - (current * ri); + ihc_coeffs->just_half_wave_rectify = false; + ihc_coeffs->lpf_coeff = 1 - exp( -1 / (ihc_params.tau_lpf * fs)); + ihc_coeffs->out1_rate = ro / (ihc_params.tau1_out * fs); + ihc_coeffs->in1_rate = 1 / (ihc_params.tau1_in * fs); + ihc_coeffs->one_capacitor = ihc_params.one_capacitor; + ihc_coeffs->output_gain = 1 / (saturation_output - current); + ihc_coeffs->rest_output = current / (saturation_output - current); + ihc_coeffs->rest_cap1 = ihc_coeffs->cap1_voltage; } else { FPType ro = 1 / conduct_at_10; - FPType c2 = ihc_params.tau2_out_ / ro; - FPType r2 = ihc_params.tau2_in_ / c2; - FPType c1 = ihc_params.tau1_out_ / r2; - FPType r1 = ihc_params.tau1_in_ / c1; + FPType c2 = ihc_params.tau2_out / ro; + FPType r2 = ihc_params.tau2_in / c2; + FPType c1 = ihc_params.tau1_out / r2; + FPType r1 = ihc_params.tau1_in / c1; FPType saturation_output = 1 / (2 * ro + r2 + r1); FPType r0 = 1 / conduct_at_0; FPType current = 1 / (r1 + r2 + r0); - ihc_coeffs->cap1_voltage_ = 1 - (current * r1); - ihc_coeffs->cap2_voltage_ = ihc_coeffs->cap1_voltage_ - (current * r2); - ihc_coeffs->just_half_wave_rectify_ = false; - ihc_coeffs->lpf_coeff_ = 1 - exp(-1 / (ihc_params.tau_lpf_ * fs)); - ihc_coeffs->out1_rate_ = 1 / (ihc_params.tau1_out_ * fs); - ihc_coeffs->in1_rate_ = 1 / (ihc_params.tau1_in_ * fs); - ihc_coeffs->out2_rate_ = ro / (ihc_params.tau2_out_ * fs); - ihc_coeffs->in2_rate_ = 1 / (ihc_params.tau2_in_ * fs); - ihc_coeffs->one_capacitor_ = ihc_params.one_capacitor_; - ihc_coeffs->output_gain_ = 1 / (saturation_output - current); - ihc_coeffs->rest_output_ = current / (saturation_output - current); - ihc_coeffs->rest_cap1_ = ihc_coeffs->cap1_voltage_; - ihc_coeffs->rest_cap2_ = ihc_coeffs->cap2_voltage_; + ihc_coeffs->cap1_voltage = 1 - (current * r1); + ihc_coeffs->cap2_voltage = ihc_coeffs->cap1_voltage - (current * r2); + ihc_coeffs->just_half_wave_rectify = false; + ihc_coeffs->lpf_coeff = 1 - exp(-1 / (ihc_params.tau_lpf * fs)); + ihc_coeffs->out1_rate = 1 / (ihc_params.tau1_out * fs); + ihc_coeffs->in1_rate = 1 / (ihc_params.tau1_in * fs); + ihc_coeffs->out2_rate = ro / (ihc_params.tau2_out * fs); + ihc_coeffs->in2_rate = 1 / (ihc_params.tau2_in * fs); + ihc_coeffs->one_capacitor = ihc_params.one_capacitor; + ihc_coeffs->output_gain = 1 / (saturation_output - current); + ihc_coeffs->rest_output = current / (saturation_output - current); + ihc_coeffs->rest_cap1 = ihc_coeffs->cap1_voltage; + ihc_coeffs->rest_cap2 = ihc_coeffs->cap2_voltage; } } - ihc_coeffs->ac_coeff_ = 2 * kPi * ihc_params.ac_corner_hz_ / fs; + ihc_coeffs->ac_coeff = 2 * kPi * ihc_params.ac_corner_hz / fs; } void CARFAC::DesignAGCCoeffs(const AGCParams& agc_params, const FPType fs, vector<AGCCoeffs>* agc_coeffs) { - agc_coeffs->resize(agc_params.n_stages_); + agc_coeffs->resize(agc_params.n_stages); FPType previous_stage_gain = 0.0; FPType decim = 1.0; - for (int stage = 0; stage < agc_params.n_stages_; ++stage) { + for (int stage = 0; stage < agc_params.n_stages; ++stage) { AGCCoeffs& agc_coeff = agc_coeffs->at(stage); - agc_coeff.n_agc_stages_ = agc_params.n_stages_; - agc_coeff.agc_stage_gain_ = agc_params.agc_stage_gain_; - vector<FPType> agc1_scales = agc_params.agc1_scales_; - vector<FPType> agc2_scales = agc_params.agc2_scales_; - vector<FPType> time_constants = agc_params.time_constants_; - FPType mix_coeff = agc_params.agc_mix_coeff_; - agc_coeff.decimation_ = agc_params.decimation_[stage]; + agc_coeff.n_agc_stages = agc_params.n_stages; + agc_coeff.agc_stage_gain = agc_params.agc_stage_gain; + vector<FPType> agc1_scales = agc_params.agc1_scales; + vector<FPType> agc2_scales = agc_params.agc2_scales; + vector<FPType> time_constants = agc_params.time_constants; + FPType mix_coeff = agc_params.agc_mix_coeff; + agc_coeff.decimation = agc_params.decimation[stage]; FPType total_dc_gain = previous_stage_gain; // Here we calculate the parameters for the current stage. FPType tau = time_constants[stage]; - agc_coeff.decim_ = decim; - agc_coeff.decim_ *= agc_coeff.decimation_; - agc_coeff.agc_epsilon_ = 1 - exp((-1 * agc_coeff.decim_) / (tau * fs)); - FPType n_times = tau * (fs / agc_coeff.decim_); + agc_coeff.decim = decim; + agc_coeff.decim *= agc_coeff.decimation; + agc_coeff.agc_epsilon = 1 - exp((-1 * agc_coeff.decim) / (tau * fs)); + FPType n_times = tau * (fs / agc_coeff.decim); FPType delay = (agc2_scales[stage] - agc1_scales[stage]) / n_times; FPType spread_sq = (pow(agc1_scales[stage], 2) + pow(agc2_scales[stage], 2)) / n_times; FPType u = 1 + (1 / spread_sq); FPType p = u - sqrt(pow(u, 2) - 1); FPType dp = delay * (1 - (2 * p) + (p*p)) / 2; - agc_coeff.agc_pole_z1_ = p - dp; - agc_coeff.agc_pole_z2_ = p + dp; + agc_coeff.agc_pole_z1 = p - dp; + agc_coeff.agc_pole_z2 = p + dp; int n_taps = 0; bool fir_ok = false; int n_iterations = 1; @@ -333,17 +334,17 @@ } // Once we have the FIR design for this stage we can assign it to the // appropriate data members. - agc_coeff.agc_spatial_iterations_ = n_iterations; - agc_coeff.agc_spatial_n_taps_ = n_taps; - agc_coeff.agc_spatial_fir_left_ = fir_left; - agc_coeff.agc_spatial_fir_mid_ = fir_mid; - agc_coeff.agc_spatial_fir_right_ = fir_right; - total_dc_gain += pow(agc_coeff.agc_stage_gain_, stage); - agc_coeff.agc_mix_coeffs_ = stage == 0 ? 0 : mix_coeff / - (tau * (fs / agc_coeff.decim_)); - agc_coeff.agc_gain_ = total_dc_gain; - agc_coeff.detect_scale_ = 1 / total_dc_gain; - previous_stage_gain = agc_coeff.agc_gain_; - decim = agc_coeff.decim_; + agc_coeff.agc_spatial_iterations = n_iterations; + agc_coeff.agc_spatial_n_taps = n_taps; + agc_coeff.agc_spatial_fir_left = fir_left; + agc_coeff.agc_spatial_fir_mid = fir_mid; + agc_coeff.agc_spatial_fir_right = fir_right; + total_dc_gain += pow(agc_coeff.agc_stage_gain, stage); + agc_coeff.agc_mix_coeffs = stage == 0 ? 0 : mix_coeff / + (tau * (fs / agc_coeff.decim)); + agc_coeff.agc_gain = total_dc_gain; + agc_coeff.detect_scale = 1 / total_dc_gain; + previous_stage_gain = agc_coeff.agc_gain; + decim = agc_coeff.decim; } -} +} \ No newline at end of file
--- a/trunk/carfac/carfac.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/carfac.h Wed May 29 15:37:28 2013 +0000 @@ -36,9 +36,18 @@ // processing sound signals. These both take two dimensional Eigen float arrays // (samples x channels) as arguments and return CARFACOutput objects. -#ifndef CARFAC_Open_Source_C__Library_CARFAC_h -#define CARFAC_Open_Source_C__Library_CARFAC_h +#ifndef CARFAC_CARFAC_H +#define CARFAC_CARFAC_H +#include <vector> +#include "carfac_common.h" +#include "car_params.h" +#include "car_coeffs.h" +#include "ihc_params.h" +#include "ihc_coeffs.h" +#include "agc_params.h" +#include "agc_coeffs.h" +#include "ear.h" #include "carfac_output.h" class CARFAC { @@ -78,4 +87,4 @@ FloatArray pole_freqs_; }; -#endif +#endif // CARFAC_CARFAC_H \ No newline at end of file
--- a/trunk/carfac/carfac_common.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/carfac_common.h Wed May 29 15:37:28 2013 +0000 @@ -37,22 +37,16 @@ // library. The remainder of the code uses this type for specifying floating // point scalars. // -// Two additional typedefs are defined for one and two dimensional arrays: -// FloatArray and FloatArray2d. These in turn make use of FPType so that the -// precision level across floating point data is consistent. +// An additional typedefs are defined for one dimensional arrays: FloatArray. +// These in turn make use of FPType so that the precision level across floating +// point data is consistent. // // The functions 'ERBHz' and 'CARFACDetect' are defined here, and are used // during the design stage of a CARFAC model. -#ifndef CARFAC_Open_Source_C__Library_CARFACCommon_h -#define CARFAC_Open_Source_C__Library_CARFACCommon_h +#ifndef CARFAC_CARFAC_COMMON_H +#define CARFAC_CARFAC_COMMON_H -// This section is where the base include operations for the CARFAC project -// occur. -// <math.h> is used during coefficient calculations and runtime operations. -#include <math.h> -//<vector> is used to store two dimensional data structures. -#include <vector> // The Eigen library is used extensively for floating point arrays. // For more information, see: http://eigen.tuxfamily.org #include <Eigen/Dense> @@ -83,4 +77,4 @@ // values. This is here because it is called both in design and run phases. FloatArray CARFACDetect (const FloatArray& x); -#endif \ No newline at end of file +#endif // CARFAC_CARFAC_COMMON_H \ No newline at end of file
--- a/trunk/carfac/carfac_output.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/carfac_output.h Wed May 29 15:37:28 2013 +0000 @@ -34,10 +34,12 @@ // EarOutput sub-objects once the target data dimensions ears (n_ears), channels // (n_ch) and timepoints (n_tp) are known. -#ifndef CARFAC_Open_Source_C__Library_carfac_output_h -#define CARFAC_Open_Source_C__Library_carfac_output_h +#ifndef CARFAC_CARFAC_OUTPUT_H +#define CARFAC_CARFAC_OUTPUT_H #include <deque> +#include <vector> +#include "carfac_common.h" #include "ear.h" class CARFACOutput { @@ -66,4 +68,4 @@ std::deque<std::vector<FloatArray>> agc_; }; -#endif +#endif // CARFAC_CARFAC_OUTPUT_H \ No newline at end of file
--- a/trunk/carfac/carfac_test.cc Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/carfac_test.cc Wed May 29 15:37:28 2013 +0000 @@ -22,8 +22,11 @@ #include <string> #include <fstream> -// GoogleTest is now included for running unit tests +#include <vector> #include <gtest/gtest.h> +#include "car_params.h" +#include "ihc_params.h" +#include "agc_params.h" #include "carfac.h" using std::vector;
--- a/trunk/carfac/ear.cc Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/ear.cc Wed May 29 15:37:28 2013 +0000 @@ -44,27 +44,27 @@ } void Ear::InitCARState() { - car_state_.z1_memory_.setZero(n_ch_); - car_state_.z2_memory_.setZero(n_ch_); - car_state_.za_memory_.setZero(n_ch_); - car_state_.zb_memory_ = car_coeffs_.zr_coeffs_; - car_state_.dzb_memory_.setZero(n_ch_); - car_state_.zy_memory_.setZero(n_ch_); - car_state_.g_memory_ = car_coeffs_.g0_coeffs_; - car_state_.dg_memory_.setZero(n_ch_); + car_state_.z1_memory.setZero(n_ch_); + car_state_.z2_memory.setZero(n_ch_); + car_state_.za_memory.setZero(n_ch_); + car_state_.zb_memory = car_coeffs_.zr_coeffs; + car_state_.dzb_memory.setZero(n_ch_); + car_state_.zy_memory.setZero(n_ch_); + car_state_.g_memory = car_coeffs_.g0_coeffs; + car_state_.dg_memory.setZero(n_ch_); } void Ear::InitIHCState() { - ihc_state_.ihc_accum_ = FloatArray::Zero(n_ch_); - if (! ihc_coeffs_.just_half_wave_rectify_) { - ihc_state_.ac_coupler_.setZero(n_ch_); - ihc_state_.lpf1_state_.setConstant(n_ch_, ihc_coeffs_.rest_output_); - ihc_state_.lpf2_state_.setConstant(n_ch_, ihc_coeffs_.rest_output_); - if (ihc_coeffs_.one_capacitor_) { - ihc_state_.cap1_voltage_.setConstant(n_ch_, ihc_coeffs_.rest_cap1_); + ihc_state_.ihc_accum = FloatArray::Zero(n_ch_); + if (! ihc_coeffs_.just_half_wave_rectify) { + ihc_state_.ac_coupler.setZero(n_ch_); + ihc_state_.lpf1_state.setConstant(n_ch_, ihc_coeffs_.rest_output); + ihc_state_.lpf2_state.setConstant(n_ch_, ihc_coeffs_.rest_output); + if (ihc_coeffs_.one_capacitor) { + ihc_state_.cap1_voltage.setConstant(n_ch_, ihc_coeffs_.rest_cap1); } else { - ihc_state_.cap1_voltage_.setConstant(n_ch_, ihc_coeffs_.rest_cap1_); - ihc_state_.cap2_voltage_.setConstant(n_ch_, ihc_coeffs_.rest_cap2_); + ihc_state_.cap1_voltage.setConstant(n_ch_, ihc_coeffs_.rest_cap1); + ihc_state_.cap2_voltage.setConstant(n_ch_, ihc_coeffs_.rest_cap2); } } } @@ -73,43 +73,43 @@ int n_agc_stages = agc_coeffs_.size(); agc_state_.resize(n_agc_stages); for (auto& stage_state : agc_state_) { - stage_state.decim_phase_ = 0; - stage_state.agc_memory_.setZero(n_ch_); - stage_state.input_accum_.setZero(n_ch_); + stage_state.decim_phase = 0; + stage_state.agc_memory.setZero(n_ch_); + stage_state.input_accum.setZero(n_ch_); } } void Ear::CARStep(const FPType input) { // This interpolates g. - car_state_.g_memory_ = car_state_.g_memory_ + car_state_.dg_memory_; + car_state_.g_memory = car_state_.g_memory + car_state_.dg_memory; // This calculates the AGC interpolation state. - car_state_.zb_memory_ = car_state_.zb_memory_ + car_state_.dzb_memory_; + car_state_.zb_memory = car_state_.zb_memory + car_state_.dzb_memory; // This updates the nonlinear function of 'velocity' along with zA, which is // a delay of z2. FloatArray nonlinear_fun(n_ch_); - FloatArray velocities = car_state_.z2_memory_ - car_state_.za_memory_; + FloatArray velocities = car_state_.z2_memory - car_state_.za_memory; OHCNonlinearFunction(velocities, &nonlinear_fun); // Here, zb_memory_ * nonlinear_fun is "undamping" delta r. - FloatArray r = car_coeffs_.r1_coeffs_ + (car_state_.zb_memory_ * + FloatArray r = car_coeffs_.r1_coeffs + (car_state_.zb_memory * nonlinear_fun); - car_state_.za_memory_ = car_state_.z2_memory_; + car_state_.za_memory = car_state_.z2_memory; // Here we reduce the CAR state by r and rotate with the fixed cos/sin coeffs. - FloatArray z1 = r * ((car_coeffs_.a0_coeffs_ * car_state_.z1_memory_) - - (car_coeffs_.c0_coeffs_ * car_state_.z2_memory_)); - car_state_.z2_memory_ = r * - ((car_coeffs_.c0_coeffs_ * car_state_.z1_memory_) + - (car_coeffs_.a0_coeffs_ * car_state_.z2_memory_)); - car_state_.zy_memory_ = car_coeffs_.h_coeffs_ * car_state_.z2_memory_; + FloatArray z1 = r * ((car_coeffs_.a0_coeffs * car_state_.z1_memory) - + (car_coeffs_.c0_coeffs * car_state_.z2_memory)); + car_state_.z2_memory = r * + ((car_coeffs_.c0_coeffs * car_state_.z1_memory) + + (car_coeffs_.a0_coeffs * car_state_.z2_memory)); + car_state_.zy_memory = car_coeffs_.h_coeffs * car_state_.z2_memory; // This section ripples the input-output path, to avoid delay... // It's the only part that doesn't get computed "in parallel": FPType in_out = input; for (int ch = 0; ch < n_ch_; ch++) { z1(ch) = z1(ch) + in_out; // This performs the ripple, and saves the final channel outputs in zy. - in_out = car_state_.g_memory_(ch) * (in_out + car_state_.zy_memory_(ch)); - car_state_.zy_memory_(ch) = in_out; + in_out = car_state_.g_memory(ch) * (in_out + car_state_.zy_memory(ch)); + car_state_.zy_memory(ch) = in_out; } - car_state_.z1_memory_ = z1; + car_state_.z1_memory = z1; } // We start with a quadratic nonlinear function, and limit it via a @@ -117,57 +117,57 @@ // absolute velocities, so it will do nothing there. void Ear::OHCNonlinearFunction(const FloatArray& velocities, FloatArray* nonlinear_fun) { - *nonlinear_fun = (1 + ((velocities * car_coeffs_.velocity_scale_) + - car_coeffs_.v_offset_).square()).inverse(); + *nonlinear_fun = (1 + ((velocities * car_coeffs_.velocity_scale) + + car_coeffs_.v_offset).square()).inverse(); } // This step is a one sample-time update of the inner-hair-cell (IHC) model, // including the detection nonlinearity and either one or two capacitor state // variables. void Ear::IHCStep(const FloatArray& car_out) { - FloatArray ac_diff = car_out - ihc_state_.ac_coupler_; - ihc_state_.ac_coupler_ = ihc_state_.ac_coupler_ + - (ihc_coeffs_.ac_coeff_ * ac_diff); - if (ihc_coeffs_.just_half_wave_rectify_) { + FloatArray ac_diff = car_out - ihc_state_.ac_coupler; + ihc_state_.ac_coupler = ihc_state_.ac_coupler + + (ihc_coeffs_.ac_coeff * ac_diff); + if (ihc_coeffs_.just_half_wave_rectify) { FloatArray output(n_ch_); for (int ch = 0; ch < n_ch_; ++ch) { FPType a = (ac_diff(ch) > 0.0) ? ac_diff(ch) : 0.0; output(ch) = (a < 2) ? a : 2; } - ihc_state_.ihc_out_ = output; + ihc_state_.ihc_out = output; } else { FloatArray conductance = CARFACDetect(ac_diff); - if (ihc_coeffs_.one_capacitor_) { - ihc_state_.ihc_out_ = conductance * ihc_state_.cap1_voltage_; - ihc_state_.cap1_voltage_ = ihc_state_.cap1_voltage_ - - (ihc_state_.ihc_out_ * ihc_coeffs_.out1_rate_) + - ((1 - ihc_state_.cap1_voltage_) * ihc_coeffs_.in1_rate_); + if (ihc_coeffs_.one_capacitor) { + ihc_state_.ihc_out = conductance * ihc_state_.cap1_voltage; + ihc_state_.cap1_voltage = ihc_state_.cap1_voltage - + (ihc_state_.ihc_out * ihc_coeffs_.out1_rate) + + ((1 - ihc_state_.cap1_voltage) * ihc_coeffs_.in1_rate); } else { - ihc_state_.ihc_out_ = conductance * ihc_state_.cap2_voltage_; - ihc_state_.cap1_voltage_ = ihc_state_.cap1_voltage_ - - ((ihc_state_.cap1_voltage_ - ihc_state_.cap2_voltage_) - * ihc_coeffs_.out1_rate_) + ((1 - ihc_state_.cap1_voltage_) * - ihc_coeffs_.in1_rate_); - ihc_state_.cap2_voltage_ = ihc_state_.cap2_voltage_ - - (ihc_state_.ihc_out_ * ihc_coeffs_.out2_rate_) + - ((ihc_state_.cap1_voltage_ - ihc_state_.cap2_voltage_) - * ihc_coeffs_.in2_rate_); + ihc_state_.ihc_out = conductance * ihc_state_.cap2_voltage; + ihc_state_.cap1_voltage = ihc_state_.cap1_voltage - + ((ihc_state_.cap1_voltage - ihc_state_.cap2_voltage) + * ihc_coeffs_.out1_rate) + ((1 - ihc_state_.cap1_voltage) * + ihc_coeffs_.in1_rate); + ihc_state_.cap2_voltage = ihc_state_.cap2_voltage - + (ihc_state_.ihc_out * ihc_coeffs_.out2_rate) + + ((ihc_state_.cap1_voltage - ihc_state_.cap2_voltage) + * ihc_coeffs_.in2_rate); } // Here we smooth the output twice using a LPF. - ihc_state_.ihc_out_ *= ihc_coeffs_.output_gain_; - ihc_state_.lpf1_state_ += ihc_coeffs_.lpf_coeff_ * - (ihc_state_.ihc_out_ - ihc_state_.lpf1_state_); - ihc_state_.lpf2_state_ += ihc_coeffs_.lpf_coeff_ * - (ihc_state_.lpf1_state_ - ihc_state_.lpf2_state_); - ihc_state_.ihc_out_ = ihc_state_.lpf2_state_ - ihc_coeffs_.rest_output_; + ihc_state_.ihc_out *= ihc_coeffs_.output_gain; + ihc_state_.lpf1_state += ihc_coeffs_.lpf_coeff * + (ihc_state_.ihc_out - ihc_state_.lpf1_state); + ihc_state_.lpf2_state += ihc_coeffs_.lpf_coeff * + (ihc_state_.lpf1_state - ihc_state_.lpf2_state); + ihc_state_.ihc_out = ihc_state_.lpf2_state - ihc_coeffs_.rest_output; } - ihc_state_.ihc_accum_ += ihc_state_.ihc_out_; + ihc_state_.ihc_accum += ihc_state_.ihc_out; } bool Ear::AGCStep(const FloatArray& ihc_out) { int stage = 0; - int n_stages = agc_coeffs_[0].n_agc_stages_; - FPType detect_scale = agc_coeffs_[n_stages - 1].detect_scale_; + int n_stages = agc_coeffs_[0].n_agc_stages; + FPType detect_scale = agc_coeffs_[n_stages - 1].detect_scale; bool updated = AGCRecurse(stage, detect_scale * ihc_out); return updated; } @@ -177,33 +177,33 @@ const auto& agc_coeffs = agc_coeffs_[stage]; auto& agc_state = agc_state_[stage]; // This is the decim factor for this stage, relative to input or prev. stage: - int decim = agc_coeffs.decimation_; + int decim = agc_coeffs.decimation; // This is the decim phase of this stage (do work on phase 0 only): - int decim_phase = agc_state.decim_phase_ + 1; + int decim_phase = agc_state.decim_phase + 1; decim_phase = decim_phase % decim; - agc_state.decim_phase_ = decim_phase; + agc_state.decim_phase = decim_phase; // Here we accumulate input for this stage from the previous stage: - agc_state.input_accum_ += agc_in; + agc_state.input_accum += agc_in; // We don't do anything if it's not the right decim_phase. if (decim_phase == 0) { // Now we do lots of work, at the decimated rate. // These are the decimated inputs for this stage, which will be further // decimated at the next stage. - agc_in = agc_state.input_accum_ / decim; + agc_in = agc_state.input_accum / decim; // This resets the accumulator. - agc_state.input_accum_ = FloatArray::Zero(n_ch_); + agc_state.input_accum = FloatArray::Zero(n_ch_); if (stage < (agc_coeffs_.size() - 1)) { // Now we recurse to evaluate the next stage(s). updated = AGCRecurse(stage + 1, agc_in); // Afterwards we add its output to this stage input, whether it updated or // not. - agc_in += agc_coeffs.agc_stage_gain_ * - agc_state_[stage + 1].agc_memory_; + agc_in += agc_coeffs.agc_stage_gain * + agc_state_[stage + 1].agc_memory; } // This performs a first-order recursive smoothing filter update, in time. - agc_state.agc_memory_ += agc_coeffs.agc_epsilon_ * - (agc_in - agc_state.agc_memory_); - AGCSpatialSmooth(agc_coeffs_[stage], &agc_state.agc_memory_); + agc_state.agc_memory += agc_coeffs.agc_epsilon * + (agc_in - agc_state.agc_memory); + AGCSpatialSmooth(agc_coeffs_[stage], &agc_state.agc_memory); updated = true; } else { updated = false; @@ -213,18 +213,18 @@ void Ear::AGCSpatialSmooth(const AGCCoeffs& agc_coeffs, FloatArray* stage_state) { - int n_iterations = agc_coeffs.agc_spatial_iterations_; + int n_iterations = agc_coeffs.agc_spatial_iterations; bool use_fir; use_fir = (n_iterations < 4) ? true : false; if (use_fir) { - FPType fir_coeffs_left = agc_coeffs.agc_spatial_fir_left_; - FPType fir_coeffs_mid = agc_coeffs.agc_spatial_fir_mid_; - FPType fir_coeffs_right = agc_coeffs.agc_spatial_fir_right_; + FPType fir_coeffs_left = agc_coeffs.agc_spatial_fir_left; + FPType fir_coeffs_mid = agc_coeffs.agc_spatial_fir_mid; + FPType fir_coeffs_right = agc_coeffs.agc_spatial_fir_right; FloatArray ss_tap1(n_ch_); FloatArray ss_tap2(n_ch_); FloatArray ss_tap3(n_ch_); FloatArray ss_tap4(n_ch_); - int n_taps = agc_coeffs.agc_spatial_n_taps_; + int n_taps = agc_coeffs.agc_spatial_n_taps; // This initializes the first two taps of stage state, which are used for // both possible cases. ss_tap1(0) = (*stage_state)(0); @@ -256,8 +256,8 @@ break; } } else { - AGCSmoothDoubleExponential(agc_coeffs.agc_pole_z1_, - agc_coeffs.agc_pole_z2_, stage_state); + AGCSmoothDoubleExponential(agc_coeffs.agc_pole_z1, agc_coeffs.agc_pole_z2, + stage_state); } } @@ -284,8 +284,8 @@ } FloatArray Ear::StageGValue(const FloatArray& undamping) { - FloatArray r = car_coeffs_.r1_coeffs_ + car_coeffs_.zr_coeffs_ * undamping; - return (1 - 2 * r * car_coeffs_.a0_coeffs_ + (r * r)) / - (1 - 2 * r * car_coeffs_.a0_coeffs_ + car_coeffs_.h_coeffs_ * r * - car_coeffs_.c0_coeffs_ + (r * r)); + FloatArray r = car_coeffs_.r1_coeffs + car_coeffs_.zr_coeffs * undamping; + return (1 - 2 * r * car_coeffs_.a0_coeffs + (r * r)) / + (1 - 2 * r * car_coeffs_.a0_coeffs + car_coeffs_.h_coeffs * r * + car_coeffs_.c0_coeffs + (r * r)); } \ No newline at end of file
--- a/trunk/carfac/ear.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/ear.h Wed May 29 15:37:28 2013 +0000 @@ -20,9 +20,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_Ear_h -#define CARFAC_Open_Source_C__Library_Ear_h +#ifndef CARFAC_EAR_H +#define CARFAC_EAR_H +#include <vector> +#include "carfac_common.h" +#include "car_coeffs.h" +#include "ihc_coeffs.h" +#include "agc_coeffs.h" #include "car_state.h" #include "ihc_state.h" #include "agc_state.h" @@ -32,8 +37,8 @@ // This is the primary initialization function that is called for each // Ear object in the CARFAC 'Design' method. void InitEar(const int n_ch, const FPType fs, - const CARCoeffs& car_params, const IHCCoeffs& ihc_params, - const std::vector<AGCCoeffs>& agc_params); + const CARCoeffs& car_coeffs, const IHCCoeffs& ihc_coeffs, + const std::vector<AGCCoeffs>& agc_coeffs); // These three methods apply the different stages of the model in sequence // to individual audio samples. void CARStep(const FPType input); @@ -41,39 +46,39 @@ bool AGCStep(const FloatArray& ihc_out); // These accessor functions return portions of the CAR state for storage in // the CAROutput structures. - const FloatArray& za_memory() { return car_state_.za_memory_; } - const FloatArray& zb_memory() { return car_state_.zb_memory_; } + const FloatArray& za_memory() { return car_state_.za_memory; } + const FloatArray& zb_memory() { return car_state_.zb_memory; } // The zy_memory_ of the CARState is equivalent to the CAR output. A second // accessor function is included for documentation purposes. - const FloatArray& zy_memory() { return car_state_.zy_memory_; } - const FloatArray& car_out() { return car_state_.zy_memory_; } - const FloatArray& g_memory() { return car_state_.g_memory_; } + const FloatArray& zy_memory() { return car_state_.zy_memory; } + const FloatArray& car_out() { return car_state_.zy_memory; } + const FloatArray& g_memory() { return car_state_.g_memory; } // This returns the IHC output for storage. - const FloatArray& ihc_out() { return ihc_state_.ihc_out_; } - const FloatArray& dzb_memory() { return car_state_.dzb_memory_; } + const FloatArray& ihc_out() { return ihc_state_.ihc_out; } + const FloatArray& dzb_memory() { return car_state_.dzb_memory; } // These accessor functions return CAR coefficients. - const FloatArray& zr_coeffs() { return car_coeffs_.zr_coeffs_; } + const FloatArray& zr_coeffs() { return car_coeffs_.zr_coeffs; } // These accessor functions return portions of the AGC state during the cross // coupling of the ears. const int agc_nstages() { return agc_coeffs_.size(); } const int agc_decim_phase(const int stage) { - return agc_state_[stage].decim_phase_; } + return agc_state_[stage].decim_phase; } const FPType agc_mix_coeff(const int stage) { - return agc_coeffs_[stage].agc_mix_coeffs_; } + return agc_coeffs_[stage].agc_mix_coeffs; } const FloatArray& agc_memory(const int stage) { - return agc_state_[stage].agc_memory_; } + return agc_state_[stage].agc_memory; } const int agc_decimation(const int stage) { - return agc_coeffs_[stage].decimation_; } + return agc_coeffs_[stage].decimation; } // This returns the stage G value during the closing of the AGC loop. FloatArray StageGValue(const FloatArray& undamping); // This function sets the AGC memory during the cross coupling stage. void set_agc_memory(const int stage, const FloatArray& new_values) { - agc_state_[stage].agc_memory_ = new_values; } + agc_state_[stage].agc_memory = new_values; } // These are the setter functions for the CAR memory states. void set_dzb_memory(const FloatArray& new_values) { - car_state_.dzb_memory_ = new_values; } + car_state_.dzb_memory = new_values; } void set_dg_memory(const FloatArray& new_values) { - car_state_.dg_memory_ = new_values; } + car_state_.dg_memory = new_values; } private: // These are the corresponding methods that initialize the model state @@ -99,4 +104,4 @@ int n_ch_; }; -#endif +#endif // CARFAC_EAR_H \ No newline at end of file
--- a/trunk/carfac/ihc_coeffs.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/ihc_coeffs.h Wed May 29 15:37:28 2013 +0000 @@ -20,26 +20,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_IHCCoeffs_h -#define CARFAC_Open_Source_C__Library_IHCCoeffs_h +#ifndef CARFAC_IHC_COEFFS_H +#define CARFAC_IHC_COEFFS_H -#include "ihc_params.h" +#include "carfac_common.h" struct IHCCoeffs { - bool just_half_wave_rectify_; - bool one_capacitor_; - FPType lpf_coeff_; - FPType out1_rate_; - FPType in1_rate_; - FPType out2_rate_; - FPType in2_rate_; - FPType output_gain_; - FPType rest_output_; - FPType rest_cap1_; - FPType rest_cap2_; - FPType ac_coeff_; - FPType cap1_voltage_; - FPType cap2_voltage_; + bool just_half_wave_rectify; + bool one_capacitor; + FPType lpf_coeff; + FPType out1_rate; + FPType in1_rate; + FPType out2_rate; + FPType in2_rate; + FPType output_gain; + FPType rest_output; + FPType rest_cap1; + FPType rest_cap2; + FPType ac_coeff; + FPType cap1_voltage; + FPType cap2_voltage; }; -#endif \ No newline at end of file +#endif // CARFAC_IHC_COEFFS_H \ No newline at end of file
--- a/trunk/carfac/ihc_params.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/ihc_params.h Wed May 29 15:37:28 2013 +0000 @@ -20,30 +20,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_IHCParams_h -#define CARFAC_Open_Source_C__Library_IHCParams_h +#ifndef CARFAC_IHC_PARAMS_H +#define CARFAC_IHC_PARAMS_H #include "carfac_common.h" struct IHCParams { IHCParams() { - just_half_wave_rectify_ = false; - one_capacitor_ = true; - tau_lpf_ = 0.000080; - tau1_out_ = 0.0005; - tau1_in_ = 0.010; - tau2_out_ = 0.0025; - tau2_in_ = 0.005; - ac_corner_hz_ = 20.0; + just_half_wave_rectify = false; + one_capacitor = true; + tau_lpf = 0.000080; + tau1_out = 0.0005; + tau1_in = 0.010; + tau2_out = 0.0025; + tau2_in = 0.005; + ac_corner_hz = 20.0; }; - bool just_half_wave_rectify_; - bool one_capacitor_; - FPType tau_lpf_; - FPType tau1_out_; - FPType tau1_in_; - FPType tau2_out_; - FPType tau2_in_; - FPType ac_corner_hz_; + bool just_half_wave_rectify; + bool one_capacitor; + FPType tau_lpf; + FPType tau1_out; + FPType tau1_in; + FPType tau2_out; + FPType tau2_in; + FPType ac_corner_hz; }; -#endif \ No newline at end of file +#endif // CARFAC_IHC_PARAMS_H \ No newline at end of file
--- a/trunk/carfac/ihc_state.h Tue May 28 17:54:18 2013 +0000 +++ b/trunk/carfac/ihc_state.h Wed May 29 15:37:28 2013 +0000 @@ -20,19 +20,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef CARFAC_Open_Source_C__Library_IHCState_h -#define CARFAC_Open_Source_C__Library_IHCState_h +#ifndef CARFAC_IHC_STATE_H +#define CARFAC_IHC_STATE_H -#include "ihc_coeffs.h" +#include "carfac_common.h" struct IHCState { - FloatArray ihc_out_; - FloatArray ihc_accum_; - FloatArray cap1_voltage_; - FloatArray cap2_voltage_; - FloatArray lpf1_state_; - FloatArray lpf2_state_; - FloatArray ac_coupler_; + FloatArray ihc_out; + FloatArray ihc_accum; + FloatArray cap1_voltage; + FloatArray cap2_voltage; + FloatArray lpf1_state; + FloatArray lpf2_state; + FloatArray ac_coupler; }; -#endif \ No newline at end of file +#endif // CARFAC_IHC_STATE_H \ No newline at end of file