annotate branches/carfac_cpp/src/CARFAC.cpp @ 564:9c4c3675c3f8
* Added class Ear, and moved the CARFAC members AGC CAR IHC into Ear. CARFAC now holds an array of Ear. TBD what is best.
* Moved the files around, and introduced a makefile that builds unittests using GTest. (Note, GTest path is configured in makefile atm.).
- two moronic tests implemented. :)
author |
Ulf.Hammarqvist@gmail.com |
date |
Sun, 20 May 2012 22:36:47 +0000 |
parents |
0fde611fcd10 |
children |
f3dde307f4b8 |
rev |
line source |
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@564
|
7 #include "Ear.h"
|
Ulf@538
|
8
|
Ulf@545
|
9 #include "CARFAC_common.h"
|
Ulf@538
|
10
|
Ulf@544
|
11 CARFAC::CARFAC(int fs = kDefaultFs,
|
Ulf@544
|
12 CAR_parameters* car_params = new CAR_parameters(),
|
Ulf@544
|
13 IHC_parameters* ihc_params = new IHC_parameters(),
|
Ulf@564
|
14 AGC_parameters* agc_params = new AGC_parameters(),
|
Ulf@564
|
15 int n_ears = 1){
|
Ulf@538
|
16
|
Ulf@564
|
17 fs_ = fs;
|
Ulf@538
|
18
|
Ulf@545
|
19 float pole_hz = car_params->first_pole_theta_* fs / (2*kPi);
|
Ulf@545
|
20 while (pole_hz > car_params->min_pole_hz_){
|
Ulf@547
|
21 pole_freqs_.push_back(pole_hz); // TODO: STL specific
|
Ulf@545
|
22 pole_hz = pole_hz - car_params->erb_per_step_ *
|
Ulf@555
|
23 ERB_Hz(pole_hz, car_params->erb_break_freq_,
|
Ulf@555
|
24 car_params->erb_q_);
|
Ulf@545
|
25 }
|
Ulf@547
|
26 n_ch_ = pole_freqs_.size();
|
Ulf@546
|
27 max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]);
|
Ulf@546
|
28
|
Ulf@564
|
29 n_ears_ = n_ears;
|
Ulf@564
|
30 Ear* ear = new Ear(car_params, ihc_params, agc_params, pole_freqs_, n_ch_, fs);
|
Ulf@564
|
31 ears_.assign(n_ears_, *ear);
|
Ulf@545
|
32 }
|
Ulf@545
|
33
|
Ulf@545
|
34 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
|
Ulf@545
|
35 return (erb_break_freq + cf_hz) / erb_q;
|
Ulf@538
|
36 }
|
Ulf@538
|
37
|
Ulf@538
|
38 CARFAC::~CARFAC() {
|
Ulf@564
|
39 //TODO: clean up
|
Ulf@538
|
40 }
|