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@545
|
32 // replace with feeding this (as const ref) instead? Saves storing doubly
|
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@545
|
37 // move this into AGC_coefficients constructor instead
|
Ulf@545
|
38 agc_coeffs_->detect_scale_ = agc_params_->detect_scale_ /
|
Ulf@545
|
39 (ihc_coeffs_->saturation_output_ *
|
Ulf@545
|
40 agc_coeffs_->agc_gain_);
|
Ulf@545
|
41 }
|
Ulf@545
|
42
|
Ulf@545
|
43 //move this somewhere else?
|
Ulf@545
|
44 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
|
Ulf@545
|
45 return (erb_break_freq + cf_hz) / erb_q;
|
Ulf@538
|
46 }
|
Ulf@538
|
47
|
Ulf@538
|
48 CARFAC::~CARFAC() {
|
Ulf@544
|
49 delete car_coeffs_;
|
Ulf@544
|
50 delete ihc_coeffs_;
|
Ulf@544
|
51 delete agc_coeffs_;
|
Ulf@539
|
52
|
Ulf@544
|
53 //delete car_params_;
|
Ulf@544
|
54 //delete ihc_params_;
|
Ulf@544
|
55 //delete agc_params_;
|
Ulf@538
|
56 }
|