Mercurial > hg > aimc
changeset 545:e63fbe19b255
stubbed some more, and tidying
author | Ulf.Hammarqvist@gmail.com |
---|---|
date | Sat, 31 Mar 2012 17:24:08 +0000 |
parents | c666e8e0696a |
children | e5ae2ed4249c |
files | branches/carfac_cpp/src/AGC.cpp branches/carfac_cpp/src/AGC.h branches/carfac_cpp/src/CAR.cpp branches/carfac_cpp/src/CAR.h branches/carfac_cpp/src/CARFAC.cpp branches/carfac_cpp/src/CARFAC.h branches/carfac_cpp/src/CARFAC_common.h branches/carfac_cpp/src/CARFAC_common_typedefs.h branches/carfac_cpp/src/IHC.h |
diffstat | 9 files changed, 105 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/branches/carfac_cpp/src/AGC.cpp Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/AGC.cpp Sat Mar 31 17:24:08 2012 +0000 @@ -1,11 +1,10 @@ #include "AGC.h" -AGC_coefficients::AGC_coefficients(AGC_parameters* AGC_params, float fs, int n_ch) -{ +AGC_coefficients::AGC_coefficients(AGC_parameters* AGC_params, + float fs, int n_ch){ // TODO stuff goes here } -AGC_coefficients::~AGC_coefficients() -{ +AGC_coefficients::~AGC_coefficients(){ // TODO Auto-generated destructor stub }
--- a/branches/carfac_cpp/src/AGC.h Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/AGC.h Sat Mar 31 17:24:08 2012 +0000 @@ -1,23 +1,25 @@ #ifndef AGC_H_ #define AGC_H_ -#include "CARFAC_common_typedefs.h" +#include "CARFAC_common.h" class AGC_parameters { public: - AGC_parameters() - { - n_stages_ = 4; // redundant? - time_constants_ = {0.002*1, 0.002*4, 0.002*16, 0.002*64}; - agc_stage_gain_ = 2; - decimation_ = {8, 2, 2, 2}; - agc1_scales_ = {1.0, 1.4, 2.0, 2.8}; - agc2_scales_ = {1.6, 2.25, 3.2, 4.5}; - detect_scale_ = 0.25; - agc_mix_coeff_ = 0.5; + AGC_parameters(): + n_stages_(4), + time_constants_({0.002*1, 0.002*4, 0.002*16, 0.002*64}), + agc_stage_gain_(2), + decimation_({8, 2, 2, 2}), + agc1_scales_({1.0, 1.4, 2.0, 2.8}), + agc2_scales_({1.6, 2.25, 3.2, 4.5}), + detect_scale_(0.25), + agc_mix_coeff_(0.5){ + // do nothing more } - virtual ~AGC_parameters(){} + virtual ~AGC_parameters(){ + // do nothing + } int n_stages_; FloatArray time_constants_; @@ -33,8 +35,11 @@ public: AGC_coefficients(AGC_parameters*, float, int); virtual ~AGC_coefficients(); + + float detect_scale_; + float agc_gain_; private: - AGC_coefficients(){} + AGC_coefficients(); }; #endif /* AGC_H_ */
--- a/branches/carfac_cpp/src/CAR.cpp Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/CAR.cpp Sat Mar 31 17:24:08 2012 +0000 @@ -1,12 +1,11 @@ #include "CAR.h" -#include "CARFAC_common_typedefs.h" +#include "CARFAC_common.h" -CAR_coefficients::CAR_coefficients(CAR_parameters* CAR_params, float fs, FloatArray pole_freqs) -{ +CAR_coefficients::CAR_coefficients(CAR_parameters* CAR_params, float fs, + FloatArray pole_freqs){ // TODO stuff goes here } -CAR_coefficients::~CAR_coefficients() -{ +CAR_coefficients::~CAR_coefficients(){ // TODO Auto-generated destructor stub }
--- a/branches/carfac_cpp/src/CAR.h Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/CAR.h Sat Mar 31 17:24:08 2012 +0000 @@ -1,26 +1,29 @@ #ifndef CAR_H_ #define CAR_H_ -#include "CARFAC_common_typedefs.h" +#include "CARFAC_common.h" #include <cmath> -class CAR_parameters { +class CAR_parameters{ public: - CAR_parameters() + CAR_parameters(): + velocity_scale_(0.2), + v_offset_(0.01), + v2_corner_(0.2), + v_damp_max_(0.01), + min_zeta_(0.10), + first_pole_theta_(0.085*kPi), + zero_ratio_(sqrt(2)), + high_f_damping_compression_(0.5), + erb_per_step_(0.5), + min_pole_hz_(30) { - velocity_scale_ = 0.2; - v_offset_ = 0.01; - v2_corner_ = 0.2; - v_damp_max_ = 0.01; - min_zeta_ = 0.10; - first_pole_theta_ = 0.085*kPi; - zero_ratio_ = sqrt(2); - high_f_damping_compression_ = 0.5; - erb_per_step_ = 0.5; - min_pole_Hz_ = 30; + // do nothing more } - virtual ~CAR_parameters(){} + virtual ~CAR_parameters(){ + // do nothing + } float velocity_scale_; float v_offset_; @@ -31,7 +34,7 @@ float zero_ratio_; float high_f_damping_compression_; float erb_per_step_; - float min_pole_Hz_; + float min_pole_hz_; }; class CAR_coefficients{ @@ -39,7 +42,7 @@ CAR_coefficients(CAR_parameters*, float, FloatArray); virtual ~CAR_coefficients(); private: - CAR_coefficients(){} + CAR_coefficients(); }; #endif /* CAR_H_ */
--- a/branches/carfac_cpp/src/CARFAC.cpp Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/CARFAC.cpp Sat Mar 31 17:24:08 2012 +0000 @@ -3,27 +3,42 @@ #include "IHC.h" #include "AGC.h" -#include "CARFAC_common_typedefs.h" +#include "CARFAC_common.h" CARFAC::CARFAC(int fs = kDefaultFs, CAR_parameters* car_params = new CAR_parameters(), IHC_parameters* ihc_params = new IHC_parameters(), AGC_parameters* agc_params = new AGC_parameters(), float erb_break_freq = kDefaultErbBreakFreq, - float erb_q = kDefaultErbQ){ + float erb_q = kDefaultErbQ) : n_ears_(0) { - // for now, design is to take ownership. Preferences? Make copies, call by value, etc? + // Design is to take ownership. Preferences? Make copies, call by value, etc? car_params_ = car_params; ihc_params_ = ihc_params; agc_params_ = agc_params; - FloatArray pole_freqs; //TODO: do it - car_coeffs_ = new CAR_coefficients(car_params_, fs, pole_freqs); + float pole_hz = car_params->first_pole_theta_* fs / (2*kPi); + while (pole_hz > car_params->min_pole_hz_){ + pole_freqs_.push_back(pole_hz); // STL specific + pole_hz = pole_hz - car_params->erb_per_step_ * + ERB_Hz(pole_hz, erb_break_freq, erb_q); + } + n_ch_ = pole_freqs_.size(); // STL specific - int n_ch = 10; // TODO: do the design loops - agc_coeffs_ = new AGC_coefficients(agc_params_, fs, n_ch); + // replace with feeding this (as const ref) instead? Saves storing doubly + car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_); + ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_); + agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_); - ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs, n_ch); + // move this into AGC_coefficients constructor instead + agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ / + (ihc_coeffs_->saturation_output_ * + agc_coeffs_->agc_gain_); +} + +//move this somewhere else? +float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){ + return (erb_break_freq + cf_hz) / erb_q; } CARFAC::~CARFAC() {
--- a/branches/carfac_cpp/src/CARFAC.h Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/CARFAC.h Sat Mar 31 17:24:08 2012 +0000 @@ -5,10 +5,18 @@ #include "IHC.h" #include "AGC.h" +const double kDefaultErbBreakFreq = 165.3; +const double kDefaultErbQ = 1000/(24.7*4.37); +const double kDefaultFs = 22050; + class CARFAC{ public: CARFAC(int, CAR_parameters*, IHC_parameters*, AGC_parameters*, float, float); virtual ~CARFAC(); + static float ERB_Hz(float,float,float); + + float fs_; + float max_channels_per_octave_; CAR_coefficients* car_coeffs_; CAR_parameters* car_params_; @@ -16,8 +24,13 @@ IHC_coefficients* ihc_coeffs_; IHC_parameters* ihc_params_; + int n_ch_; + FloatArray pole_freqs_; + AGC_coefficients* agc_coeffs_; AGC_parameters* agc_params_; + + int n_ears_; }; #endif /* CARFAC_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/branches/carfac_cpp/src/CARFAC_common.h Sat Mar 31 17:24:08 2012 +0000 @@ -0,0 +1,9 @@ +#ifndef CARFAC_COMMON_TYPEDEFS_H_ +#define CARFAC_COMMON_TYPEDEFS_H_ + +#include <vector> + +typedef std::vector<float> FloatArray; +const double kPi = 3.1415926; + +#endif /* CARFAC_COMMON_TYPEDEFS_H_ */
--- a/branches/carfac_cpp/src/CARFAC_common_typedefs.h Thu Mar 29 19:43:36 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -#ifndef CARFAC_COMMON_TYPEDEFS_H_ -#define CARFAC_COMMON_TYPEDEFS_H_ - -#include <vector> - -typedef std::vector<float> FloatArray; - -const double kDefaultErbBreakFreq = 165.3; -const double kDefaultErbQ = 1000/(24.7*4.37); -const double kDefaultFs = 22050; - -const double kPi = 3.1415926; - -#endif /* CARFAC_COMMON_TYPEDEFS_H_ */
--- a/branches/carfac_cpp/src/IHC.h Thu Mar 29 19:43:36 2012 +0000 +++ b/branches/carfac_cpp/src/IHC.h Sat Mar 31 17:24:08 2012 +0000 @@ -2,18 +2,20 @@ #define IHC_H_ // not sure how to best deal with the "three style" IHC - ulha -class IHC_parameters { +class IHC_parameters{ public: - IHC_parameters() - { - tau_lpf_ = 0.000080; - tau1_out_ = 0.020; - tau1_in_ = 0.020; - tau2_out_ = 0.005; - tau2_in_ = 0.005; + IHC_parameters() : + tau_lpf_(0.000080), + tau1_out_(0.020), + tau1_in_(0.20), + tau2_out_(0.005), + tau2_in_(0.005){ + // do nothing more } - virtual ~IHC_parameters(){} + virtual ~IHC_parameters(){ + // do nothing + } float tau_lpf_; float tau1_out_; @@ -22,12 +24,15 @@ float tau2_in_; }; -class IHC_coefficients { +class IHC_coefficients{ public: IHC_coefficients(IHC_parameters*, float, int); virtual ~IHC_coefficients(); + + float saturation_output_; + private: - IHC_coefficients(){} + IHC_coefficients(); }; #endif /* IHC_H_ */