Mercurial > hg > aimc
comparison branches/carfac_cpp/src/CARFAC.cpp @ 555:4de3bebec3d6
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 | 42f8ed31b2b1 |
children | 0fde611fcd10 |
comparison
equal
deleted
inserted
replaced
554:d18ff10b5559 | 555:4de3bebec3d6 |
---|---|
8 #include "CARFAC_common.h" | 8 #include "CARFAC_common.h" |
9 | 9 |
10 CARFAC::CARFAC(int fs = kDefaultFs, | 10 CARFAC::CARFAC(int fs = kDefaultFs, |
11 CAR_parameters* car_params = new CAR_parameters(), | 11 CAR_parameters* car_params = new CAR_parameters(), |
12 IHC_parameters* ihc_params = new IHC_parameters(), | 12 IHC_parameters* ihc_params = new IHC_parameters(), |
13 AGC_parameters* agc_params = new AGC_parameters(), | 13 AGC_parameters* agc_params = new AGC_parameters()) : n_ears_(0) { |
14 float erb_break_freq = kDefaultErbBreakFreq, | |
15 float erb_q = kDefaultErbQ) : n_ears_(0) { | |
16 | 14 |
17 // Design is to take ownership. Preferences? Make copies, call by value, etc? | 15 // Design is to take ownership. Preferences? Make copies, call by value, etc? |
18 car_params_ = car_params; | 16 car_params_ = car_params; |
19 ihc_params_ = ihc_params; | 17 ihc_params_ = ihc_params; |
20 agc_params_ = agc_params; | 18 agc_params_ = agc_params; |
21 | 19 |
22 float pole_hz = car_params->first_pole_theta_* fs / (2*kPi); | 20 float pole_hz = car_params->first_pole_theta_* fs / (2*kPi); |
23 while (pole_hz > car_params->min_pole_hz_){ | 21 while (pole_hz > car_params->min_pole_hz_){ |
24 pole_freqs_.push_back(pole_hz); // TODO: STL specific | 22 pole_freqs_.push_back(pole_hz); // TODO: STL specific |
25 pole_hz = pole_hz - car_params->erb_per_step_ * | 23 pole_hz = pole_hz - car_params->erb_per_step_ * |
26 ERB_Hz(pole_hz, erb_break_freq, erb_q); | 24 ERB_Hz(pole_hz, car_params->erb_break_freq_, |
25 car_params->erb_q_); | |
27 } | 26 } |
28 n_ch_ = pole_freqs_.size(); | 27 n_ch_ = pole_freqs_.size(); |
29 | 28 |
30 max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]); | 29 max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]); |
31 | 30 |
33 car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_); | 32 car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_); |
34 ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_); | 33 ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_); |
35 agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_); | 34 agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_); |
36 | 35 |
37 //TODO: move this into AGC_coefficients constructor instead? This style | 36 //TODO: move this into AGC_coefficients constructor instead? This style |
38 // makes me a bit wary. | 37 // makes me (ulha) a bit wary. |
39 agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ / | 38 agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ / |
40 (ihc_coeffs_->saturation_output_ * | 39 (ihc_coeffs_->saturation_output_ * |
41 agc_coeffs_->agc_gain_); | 40 agc_coeffs_->agc_gain_); |
42 | |
43 | |
44 } | 41 } |
45 | 42 |
46 //TODO: move this somewhere else? | |
47 float CARFAC::ERB_Hz(float cf_hz){ | |
48 return ERB_Hz(cf_hz, kDefaultErbBreakFreq, kDefaultErbQ); | |
49 } // TODO: is it really intentional to use this default value thing in matlab code? | |
50 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){ | 43 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){ |
51 return (erb_break_freq + cf_hz) / erb_q; | 44 return (erb_break_freq + cf_hz) / erb_q; |
52 } | 45 } |
53 | 46 |
54 CARFAC::~CARFAC() { | 47 CARFAC::~CARFAC() { |
55 delete car_coeffs_; | 48 delete car_coeffs_; |
56 delete ihc_coeffs_; | 49 delete ihc_coeffs_; |
57 delete agc_coeffs_; | 50 delete agc_coeffs_; |
58 | 51 |
59 //TODO: as the current design takes ownership OR creates news params, | 52 //TODO: as the current design takes ownership OR creates news params, |
60 //deletion is a ambiguos. Revise this design! | 53 //deletion is a ambiguos. Revise this design? |
61 | 54 |
62 //delete car_params_; | 55 //delete car_params_; |
63 //delete ihc_params_; | 56 //delete ihc_params_; |
64 //delete agc_params_; | 57 //delete agc_params_; |
65 } | 58 } |