annotate 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
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@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@555 13 AGC_parameters* agc_params = new AGC_parameters()) : n_ears_(0) {
Ulf@538 14
Ulf@545 15 // Design is to take ownership. Preferences? Make copies, call by value, etc?
Ulf@544 16 car_params_ = car_params;
Ulf@544 17 ihc_params_ = ihc_params;
Ulf@544 18 agc_params_ = agc_params;
Ulf@538 19
Ulf@545 20 float pole_hz = car_params->first_pole_theta_* fs / (2*kPi);
Ulf@545 21 while (pole_hz > car_params->min_pole_hz_){
Ulf@547 22 pole_freqs_.push_back(pole_hz); // TODO: STL specific
Ulf@545 23 pole_hz = pole_hz - car_params->erb_per_step_ *
Ulf@555 24 ERB_Hz(pole_hz, car_params->erb_break_freq_,
Ulf@555 25 car_params->erb_q_);
Ulf@545 26 }
Ulf@547 27 n_ch_ = pole_freqs_.size();
Ulf@538 28
Ulf@546 29 max_channels_per_octave_ = log(2) / log(pole_freqs_[0]/pole_freqs_[1]);
Ulf@546 30
Ulf@551 31 //TODO: pass const references?
Ulf@545 32 car_coeffs_ = new CAR_coefficients(car_params_, fs_, pole_freqs_);
Ulf@545 33 ihc_coeffs_ = new IHC_coefficients(ihc_params_, fs_, n_ch_);
Ulf@545 34 agc_coeffs_ = new AGC_coefficients(agc_params_, fs_, n_ch_);
Ulf@542 35
Ulf@551 36 //TODO: move this into AGC_coefficients constructor instead? This style
Ulf@555 37 // makes me (ulha) a bit wary.
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 float CARFAC::ERB_Hz(float cf_hz, float erb_break_freq, float erb_q){
Ulf@545 44 return (erb_break_freq + cf_hz) / erb_q;
Ulf@538 45 }
Ulf@538 46
Ulf@538 47 CARFAC::~CARFAC() {
Ulf@544 48 delete car_coeffs_;
Ulf@544 49 delete ihc_coeffs_;
Ulf@544 50 delete agc_coeffs_;
Ulf@539 51
Ulf@551 52 //TODO: as the current design takes ownership OR creates news params,
Ulf@555 53 //deletion is a ambiguos. Revise this design?
Ulf@551 54
Ulf@544 55 //delete car_params_;
Ulf@544 56 //delete ihc_params_;
Ulf@544 57 //delete agc_params_;
Ulf@538 58 }