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@538
|
5
|
Ulf@564
|
6 CAR_coefficients::CAR_coefficients(CAR_parameters* car_params_p, float fs,
|
Ulf@545
|
7 FloatArray pole_freqs){
|
Ulf@547
|
8
|
Ulf@564
|
9 float f = pow(car_params_p->zero_ratio_, 2) + 1;
|
Ulf@547
|
10
|
Ulf@555
|
11 // TODO: dirty FloatArray initialization.
|
Ulf@548
|
12 r1_coeffs_= pole_freqs;
|
Ulf@548
|
13 a0_coeffs_= pole_freqs;
|
Ulf@548
|
14 c0_coeffs_= pole_freqs;
|
Ulf@548
|
15 h_coeffs_= pole_freqs;
|
Ulf@548
|
16 g0_coeffs_= pole_freqs;
|
Ulf@548
|
17 zr_coeffs_= pole_freqs;
|
Ulf@548
|
18
|
Ulf@547
|
19 FloatArray theta = pole_freqs;
|
Ulf@547
|
20
|
Ulf@548
|
21 float min_zeta_mod;
|
Ulf@548
|
22 float x;
|
Ulf@564
|
23 float ff = car_params_p->high_f_damping_compression_;
|
Ulf@548
|
24
|
Ulf@549
|
25 // TODO: temp loop until we get eigen in (or we just leave it like this)
|
Ulf@549
|
26 for(float i=0; i<pole_freqs.size(); i++){
|
Ulf@547
|
27 theta[i] *= (2*kPi*fs); // scalar mult.
|
Ulf@548
|
28 c0_coeffs_[i] = sin(theta[i]);
|
Ulf@548
|
29 a0_coeffs_[i] = cos(theta[i]);
|
Ulf@548
|
30
|
Ulf@548
|
31 x = theta[i]/kPi;
|
Ulf@548
|
32 zr_coeffs_[i] = kPi * (x - ff * x*x*x);
|
Ulf@548
|
33
|
Ulf@564
|
34 min_zeta_mod = (car_params_p->min_zeta_ + 0.25 * (CARFAC::ERB_Hz(
|
Ulf@564
|
35 pole_freqs[i], car_params_p->erb_break_freq_,
|
Ulf@564
|
36 car_params_p->erb_q_) / pole_freqs[i]
|
Ulf@564
|
37 - car_params_p->min_zeta_));
|
Ulf@555
|
38
|
Ulf@548
|
39 r1_coeffs_[i] = 1-zr_coeffs_[i]*min_zeta_mod;
|
Ulf@548
|
40
|
Ulf@548
|
41 h_coeffs_[i] = c0_coeffs_[i] * f;
|
Ulf@549
|
42
|
Ulf@550
|
43 //TODO: g0_coeffs_ calculated here for now. Let's talk about this, need
|
Ulf@550
|
44 // to see the whole picture of what makes sense.
|
Ulf@550
|
45 // Related: I believe CAR, IHC and AGC classes would be beneficial!
|
Ulf@550
|
46 float tmp = 1 - 2*r1_coeffs_[i]*a0_coeffs_[i] + r1_coeffs_[i]*r1_coeffs_[i];
|
Ulf@550
|
47 g0_coeffs_[i] = tmp / ( tmp + h_coeffs_[i]*r1_coeffs_[i]*c0_coeffs_[i]);
|
Ulf@547
|
48 }
|
Ulf@547
|
49
|
Ulf@538
|
50 }
|
Ulf@538
|
51
|
Ulf@545
|
52 CAR_coefficients::~CAR_coefficients(){
|
Ulf@544
|
53 // TODO Auto-generated destructor stub
|
Ulf@538
|
54 }
|