annotate branches/carfac_cpp/src/CAR.cpp @ 695:2e3672df5698

Simple integration test between CARFAC and SAI. The interface between the two classes is pretty clunky because of the way CARFACOutput stores things. We should work on this, probably by rotating the outer two dimensions of CARFACOutput (i.e. store outputs in containers with sizes n_ears x n_samples x n_channels instead of n_samples x n_ears x n_channels).
author ronw@google.com
date Wed, 26 Jun 2013 23:35:47 +0000
parents d59c0d65624b
children
rev   line source
Ulf@538 1 #include "CAR.h"
Ulf@545 2 #include "CARFAC_common.h"
Ulf@548 3 #include "CARFAC.h"
Ulf@547 4 #include <cmath>
Ulf@587 5 #include "unit_conversion.h"
Ulf@538 6
Ulf@586 7 CAR_parameters::CAR_parameters():
Ulf@586 8 velocity_scale_(0.2),
Ulf@586 9 v_offset_(0.01),
Ulf@586 10 v2_corner_(0.2),
Ulf@586 11 v_damp_max_(0.01),
Ulf@586 12 min_zeta_(0.10),
Ulf@586 13 first_pole_theta_(0.085*kPi),
Ulf@586 14 zero_ratio_(sqrt(2)),
Ulf@586 15 high_f_damping_compression_(0.5),
Ulf@586 16 erb_per_step_(0.5),
Ulf@586 17 min_pole_hz_(30),
Ulf@586 18 erb_break_freq_(kDefaultErbBreakFreq),
Ulf@586 19 erb_q_(kDefaultErbQ)
Ulf@586 20 {
Ulf@586 21 // do nothing more!
Ulf@586 22 }
Ulf@586 23
Ulf@564 24 CAR_coefficients::CAR_coefficients(CAR_parameters* car_params_p, float fs,
Ulf@586 25 FloatArray pole_freqs)
Ulf@586 26 {
Ulf@547 27
Ulf@564 28 float f = pow(car_params_p->zero_ratio_, 2) + 1;
Ulf@547 29
Ulf@555 30 // TODO: dirty FloatArray initialization.
Ulf@548 31 r1_coeffs_= pole_freqs;
Ulf@548 32 a0_coeffs_= pole_freqs;
Ulf@548 33 c0_coeffs_= pole_freqs;
Ulf@548 34 h_coeffs_= pole_freqs;
Ulf@548 35 g0_coeffs_= pole_freqs;
Ulf@548 36 zr_coeffs_= pole_freqs;
Ulf@548 37
Ulf@547 38 FloatArray theta = pole_freqs;
Ulf@547 39
Ulf@548 40 float min_zeta_mod;
Ulf@548 41 float x;
Ulf@564 42 float ff = car_params_p->high_f_damping_compression_;
Ulf@548 43
Ulf@549 44 // TODO: temp loop until we get eigen in (or we just leave it like this)
Ulf@549 45 for(float i=0; i<pole_freqs.size(); i++){
Ulf@547 46 theta[i] *= (2*kPi*fs); // scalar mult.
Ulf@548 47 c0_coeffs_[i] = sin(theta[i]);
Ulf@548 48 a0_coeffs_[i] = cos(theta[i]);
Ulf@548 49
Ulf@548 50 x = theta[i]/kPi;
Ulf@548 51 zr_coeffs_[i] = kPi * (x - ff * x*x*x);
Ulf@548 52
Ulf@587 53 min_zeta_mod = (car_params_p->min_zeta_ + 0.25 * (ERB_Hz(
Ulf@564 54 pole_freqs[i], car_params_p->erb_break_freq_,
Ulf@564 55 car_params_p->erb_q_) / pole_freqs[i]
Ulf@564 56 - car_params_p->min_zeta_));
Ulf@555 57
Ulf@548 58 r1_coeffs_[i] = 1-zr_coeffs_[i]*min_zeta_mod;
Ulf@548 59
Ulf@548 60 h_coeffs_[i] = c0_coeffs_[i] * f;
Ulf@549 61
Ulf@550 62 //TODO: g0_coeffs_ calculated here for now. Let's talk about this, need
Ulf@550 63 // to see the whole picture of what makes sense.
Ulf@550 64 // Related: I believe CAR, IHC and AGC classes would be beneficial!
Ulf@550 65 float tmp = 1 - 2*r1_coeffs_[i]*a0_coeffs_[i] + r1_coeffs_[i]*r1_coeffs_[i];
Ulf@550 66 g0_coeffs_[i] = tmp / ( tmp + h_coeffs_[i]*r1_coeffs_[i]*c0_coeffs_[i]);
Ulf@547 67 }
Ulf@547 68
Ulf@538 69 }