Ulf@546
|
1 #include <cmath>
|
Ulf@546
|
2
|
Ulf@538
|
3 #include "CARFAC.h"
|
Ulf@538
|
4 #include "CAR.h"
|
Ulf@538
|
5 #include "IHC.h"
|
Ulf@538
|
6 #include "AGC.h"
|
Ulf@538
|
7
|
Ulf@545
|
8 #include "CARFAC_common.h"
|
Ulf@538
|
9
|
Ulf@544
|
10 CARFAC::CARFAC(int fs = kDefaultFs,
|
Ulf@544
|
11 CAR_parameters* car_params = new CAR_parameters(),
|
Ulf@544
|
12 IHC_parameters* ihc_params = new IHC_parameters(),
|
Ulf@544
|
13 AGC_parameters* agc_params = new AGC_parameters(),
|
Ulf@544
|
14 float erb_break_freq = kDefaultErbBreakFreq,
|
Ulf@545
|
15 float erb_q = kDefaultErbQ) : n_ears_(0) {
|
Ulf@538
|
16
|
Ulf@545
|
17 // Design is to take ownership. Preferences? Make copies, call by value, etc?
|
Ulf@544
|
18 car_params_ = car_params;
|
Ulf@544
|
19 ihc_params_ = ihc_params;
|
Ulf@544
|
20 agc_params_ = agc_params;
|
Ulf@538
|
21
|
Ulf@545
|
22 float pole_hz = car_params->first_pole_theta_* fs / (2*kPi);
|
Ulf@545
|
23 while (pole_hz > car_params->min_pole_hz_){
|
Ulf@547
|
24 pole_freqs_.push_back(pole_hz); // TODO: STL specific
|
Ulf@545
|
25 pole_hz = pole_hz - car_params->erb_per_step_ *
|
Ulf@545
|
26 ERB_Hz(pole_hz, erb_break_freq, erb_q);
|
Ulf@545
|
27 }
|
Ulf@547
|
28 n_ch_ = pole_freqs_.size();
|
Ulf@538
|
29
|
Ulf@546
|
30 max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]);
|
Ulf@546
|
31
|
Ulf@551
|
32 //TODO: pass const references?
|
Ulf@545
|
33 car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_);
|
Ulf@545
|
34 ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_);
|
Ulf@545
|
35 agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_);
|
Ulf@542
|
36
|
Ulf@551
|
37 //TODO: move this into AGC_coefficients constructor instead? This style
|
Ulf@551
|
38 // makes me a bit wary.
|
Ulf@545
|
39 agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ /
|
Ulf@545
|
40 (ihc_coeffs_->saturation_output_ *
|
Ulf@545
|
41 agc_coeffs_->agc_gain_);
|
Ulf@548
|
42
|
Ulf@548
|
43
|
Ulf@545
|
44 }
|
Ulf@545
|
45
|
Ulf@551
|
46 //TODO: move this somewhere else?
|
Ulf@548
|
47 float CARFAC::ERB_Hz(float cf_hz){
|
Ulf@548
|
48 return ERB_Hz(cf_hz, 1000/4.37, 1000/(24.7*4.37));
|
Ulf@551
|
49 } // TODO: is it really intentional to use this default value thing in matlab code?
|
Ulf@545
|
50 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
|
Ulf@545
|
51 return (erb_break_freq + cf_hz) / erb_q;
|
Ulf@538
|
52 }
|
Ulf@538
|
53
|
Ulf@538
|
54 CARFAC::~CARFAC() {
|
Ulf@544
|
55 delete car_coeffs_;
|
Ulf@544
|
56 delete ihc_coeffs_;
|
Ulf@544
|
57 delete agc_coeffs_;
|
Ulf@539
|
58
|
Ulf@551
|
59 //TODO: as the current design takes ownership OR creates news params,
|
Ulf@551
|
60 //deletion is a ambiguos. Revise this design!
|
Ulf@551
|
61
|
Ulf@544
|
62 //delete car_params_;
|
Ulf@544
|
63 //delete ihc_params_;
|
Ulf@544
|
64 //delete agc_params_;
|
Ulf@538
|
65 }
|