annotate src/CAR.cpp @ 494:24828350536a carfac_cpp

Fixed the ERB_Hz default parameter bug also in c++ Introduced FloatMatrix to build on the concept of FloatArray typedef
author Ulf.Hammarqvist@gmail.com
date Sun, 08 Apr 2012 19:40:13 +0000
parents 20de0b60b694
children 83cd5bbf2a3e
rev   line source
Ulf@477 1 #include "CAR.h"
Ulf@484 2 #include "CARFAC_common.h"
Ulf@487 3 #include "CARFAC.h"
Ulf@486 4 #include <cmath>
Ulf@477 5
Ulf@486 6 CAR_coefficients::CAR_coefficients(CAR_parameters* car_params, float fs,
Ulf@484 7 FloatArray pole_freqs){
Ulf@486 8
Ulf@486 9 float f = pow(car_params->zero_ratio_, 2) + 1;
Ulf@486 10
Ulf@494 11 // TODO: dirty FloatArray initialization.
Ulf@487 12 r1_coeffs_= pole_freqs;
Ulf@487 13 a0_coeffs_= pole_freqs;
Ulf@487 14 c0_coeffs_= pole_freqs;
Ulf@487 15 h_coeffs_= pole_freqs;
Ulf@487 16 g0_coeffs_= pole_freqs;
Ulf@487 17 zr_coeffs_= pole_freqs;
Ulf@487 18
Ulf@486 19 FloatArray theta = pole_freqs;
Ulf@486 20
Ulf@487 21 float min_zeta_mod;
Ulf@487 22 float x;
Ulf@487 23 float ff = car_params->high_f_damping_compression_;
Ulf@487 24
Ulf@488 25 // TODO: temp loop until we get eigen in (or we just leave it like this)
Ulf@488 26 for(float i=0; i<pole_freqs.size(); i++){
Ulf@486 27 theta[i] *= (2*kPi*fs); // scalar mult.
Ulf@487 28 c0_coeffs_[i] = sin(theta[i]);
Ulf@487 29 a0_coeffs_[i] = cos(theta[i]);
Ulf@487 30
Ulf@487 31 x = theta[i]/kPi;
Ulf@487 32 zr_coeffs_[i] = kPi * (x - ff * x*x*x);
Ulf@487 33
Ulf@494 34 min_zeta_mod = (car_params->min_zeta_ + 0.25 * (CARFAC::ERB_Hz(
Ulf@494 35 pole_freqs[i], car_params->erb_break_freq_,
Ulf@494 36 car_params->erb_q_) / pole_freqs[i]
Ulf@494 37 - car_params->min_zeta_));
Ulf@494 38
Ulf@487 39 r1_coeffs_[i] = 1-zr_coeffs_[i]*min_zeta_mod;
Ulf@487 40
Ulf@487 41 h_coeffs_[i] = c0_coeffs_[i] * f;
Ulf@488 42
Ulf@489 43 //TODO: g0_coeffs_ calculated here for now. Let's talk about this, need
Ulf@489 44 // to see the whole picture of what makes sense.
Ulf@489 45 // Related: I believe CAR, IHC and AGC classes would be beneficial!
Ulf@489 46 float tmp = 1 - 2*r1_coeffs_[i]*a0_coeffs_[i] + r1_coeffs_[i]*r1_coeffs_[i];
Ulf@489 47 g0_coeffs_[i] = tmp / ( tmp + h_coeffs_[i]*r1_coeffs_[i]*c0_coeffs_[i]);
Ulf@486 48 }
Ulf@486 49
Ulf@477 50 }
Ulf@477 51
Ulf@484 52 CAR_coefficients::~CAR_coefficients(){
Ulf@483 53 // TODO Auto-generated destructor stub
Ulf@477 54 }